How to Run Linux GUI Apps With WSL2 on Windows
Windows Subsystem for Linux (WSL) 2, a new and improved version of WSL, offers a more complete Linux kernel implementation. This means that you can now run Linux graphical user interface (GUI) applications with WSL2 on Windows.
In this article, we’ll show you how to run Linux GUI apps with WSL2 on Windows.
Step 1: Install WSL2
Before you can run Linux GUI apps with WSL2 on Windows, you’ll need to set up WSL2. Here’s how:
1. Make sure you’re using Windows 10 with the latest updates installed.
2. Enable the Windows Subsystem for Linux feature in the Windows Features panel. Open the Start menu and search for “Turn Windows features on or off”. In the window that appears, scroll down and check the box next to “Windows Subsystem for Linux”. Click OK to save the changes.
3. Restart your computer when prompted.
4. Install a Linux distribution of your choice from the Microsoft Store. We recommend using Ubuntu or Debian.
5. Launch the Linux distribution from the Start menu.
6. Enter a new username and password when prompted.
Step 2: Install an X server
In order to run Linux GUI apps with WSL2 on Windows, you’ll need to install an X server. An X server is a program that allows you to display graphical user interfaces running on a remote server.
Here’s how to install an X server:
1. Download and install an X server for Windows, such as Xming or VcXsrv.
2. Launch the X server and make sure it’s running in the background.
Step 3: Configure WSL2
Now that you have WSL2 and an X server installed, you’ll need to configure WSL2 to use the X server.
1. Open the Linux distribution terminal and run the following command:
echo “export DISPLAY=localhost:0” >> ~/.bashrc
This command sets the DISPLAY environment variable to point to the X server.
2. Close the Linux distribution terminal.
3. Open a Windows command prompt or PowerShell prompt.
4. Run the following command:
5. Look for the IP address of the network adapter associated with your X server. It should be listed under “Ethernet adapter vEthernet (WSL)”.
6. Open the Linux distribution terminal again.
7. Run the following command, replacing “X.X.X.X” with the IP address of your X server:
This command sets the LIBGL_ALWAYS_INDIRECT environment variable to enable indirect rendering, which allows the Linux GUI app to run on the X server. It also sets the DISPLAY environment variable to point to the IP address of the X server.
Step 4: Run a Linux GUI app
Now that you’ve configured WSL2 to use the X server, you can run a Linux GUI app using the following command:
This command will launch the xeyes app, which displays a pair of eyes that follow your mouse cursor.
Congratulations, you’ve successfully run a Linux GUI app with WSL2 on Windows!
WSL2 offers a powerful and seamless way to run Linux GUI apps on your Windows machine. By following the steps outlined in this article, you can configure WSL2 to use an X server and easily run Linux GUI apps with just a few simple commands.