In May 2016 Microsoft came up with Windows Subsystem for Linux (WSL), and for the first time, allowed users to actually run Linux inside the Windows OS without the need of a virtual machine.
Technically speaking, WSL is a layer in the OS which enables users to natively run a Linux file system, Command line tools, Linux Binaries, GUI apps and more on Windows 10, Windows 11, and higher operating systems.
In this article we will be listing all the steps to execute GUI apps on WSL.
The latest version of the Windows Subsystem is WSL 2 that was launched in May 2019 and introduced important changes, most importantly the provision of a real Linux Kernel.
WSL / WSL 2 is available only on 64-bit versions of Windows 10 / 11 and are installed by default. For running Linux on the WSL, you need to download and install one of the available Linux Distributions (Distros) or Flavors such as Ubuntu, OpenSUSE, Debian GNU etc. from the Microsoft Store.
Here are the steps that you should follow:
1. Verify if WSL is enabled in your system by running the command wsl in the command prompt or Windows power shell. If it is not enabled, the error message will say ‘wsl is not recognized as a command’. If it is enabled it will prompt you to install a Linux Distro. Windows 10 Home must manually enable WSL by selecting ‘Windows Susbsystem for Linux’ in ‘Turn Windows Features on or off’ and clicking on ‘Ok’
2. The next step would be to download and install a Linux Distro of your choice that will run on the WSL. For this, access the Microsoft Store and search for ‘Linux’ and click on the required Distro to download and install it. For my testing, I used the Ubuntu 20.04.4 flavor.
3. Run the command wsl once again. This will bring up the SSH Terminal for your Linux Distro if it has been installed correctly in the previous step.
4. Now, to run GUI based Linux Apps on a Windows operating system you require the GWSL XServer. Search for GWSL in the Microsoft Store and download and install it. Once the installation is complete, verify that it is up and running by hovering your mouse over its ‘System Tray’ icon.
5. Next, download the scripts for running GUI apps from GitHub and more, by executing the following commands one after the other in the SSH terminal.
git clone https://github.com/hanifalisohag/Running_GUI_applications_on_wsl_windows11_or_windows10.git
cd Running_GUI_applications_on_wsl_windows11_or_windows10
sudo chmod +x gui_scripts.sh
6. Download and update the Linux package information from all the configured sources by running the following popular command at the terminal. Remember that this will take some time based on your Internet speed.
sudo apt-get update
7. In this step, we download and install the X11 Apps. This provides the basic framework for a GUI environment on Linux operating systems. It also includes the ‘xclock’ application that provides a graphical display of the system time. We will be using this program to test if the GUI apps are running successfully on WSL.
apt-get install x11-apps
8. Next, we will download and install another GUI App namely, ‘Gedit’ It’s an all-purpose text editor with a neat and simple GUI that we will be using for test purposes.
apt-get install gedit
9. Now, run the script that we downloaded above from GitHub using the following command. This script help the GUI apps in locating the GWSL XServer
./gui_script.sh
10. Finally, your WSL environment is ready with the Linux Distro to run any Linux GUI apps. Type the following commands to run the specific applications and test if they are working successfully.
xclock
gedit
I faced a problem in detection of the GWSL XServer although it was successfully running and the script to locate it was executed as described in the above steps. If you come across such a situation, run the following commands in the terminal in the same sequence as specified. This solved the issue for me, and I could run the GUI Apps.
WINDOWS_HOST=`echo $SSH_CLIENT | awk ‘{ print $1}’`
export DISPLAY=$WINDOWS_HOST:0.0
echo DISPLAY OUT to $DISPLAY
Once you have verified the above you can go ahead and try out any other Linux GUI applications on Windows.