Launch GUI App from WSL
I wanted to run an login app (aws-azure-login) from WSL which display GUI, but it could not run showing the following error — Unable to Open X-Display
Since WSL distro does not come with GUI, we need to install a X-Server on our Windows Host and Connect to it from WSL.
Install and configure
Follow the steps below to install and configure X-Server.
- Download and Install VcXsrv Windows X Server which is available from https://sourceforge.net/projects/vcxsrv/
- Configure according to screenshots below:
3. Enable Outgoing Connection from Windows Firewall -
Windows Security -> Firewall & network protection -> Allow an app through firewall -> make sure VcXsrv has both public and private checked.
4. Configure WSL to use the X-Server, you can put that at the end of ~/.bashrc to load it every log in
export DISPLAY=127.0.0.1:0.0 (wsl1)
export DISPLAY=windows_host_ip:0.0 (wsl2), replace windows_host_ip with win dows host real ip.
5. Create a .xsession file in the user home directory e.g.
echo xfce4-session > ~/.xsession
To test the above, install the following app and run it
sudo apt install x11-apps
You should be able to see a window pop up like below