How to do GUI Applications in Windows Subsystem for Linux

avatar

image.png

Everyone says you can't do GUI applications in Windows Subsystem for Linux (WSL), but did you know you really can?

In fact, you can even get a full X Windows session with WSL. I'm going to show you how.

There are two ways to do this, you run individual X applications, or you can get an entire X Windows desktop.


Launch X Windows Applications

This method is easiest and will allow you to run individual applications with ease.

You will first need an X Windows client, fortunately, there is a free option called VcXSrv.

Once you install VcXSrv, this will act as an X Server for hosting applications.

Launch the application and select the following options to start up the X Server host.

Note the disable access control on the third screenshot. You can do access control but it is a bit more complicated.

In your Linux distribution add the following line to the end of your .bashrc file.

export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0

You can either reboot your WSL instance or run this command in the shell as well to put it in your current session.

Let's install an X Windows application to test it.

sudo apt install xterm

Then just run xterm


Run a full X Windows session.

Install Xfce4

sudo apt-get -y install xfce4 && sudo apt-get -y install xubuntu-desktop

This step will take a long time, it will install a full X Windows desktop.

Once finished, you can just run startxfce4 to start the desktop.

While this works well and good, I'm going to show you an even better way to get a full desktop.

Introducing xRDP

Install xRDP Server

sudo apt-get -y install xrdp

Configure xRDP

echo xfce4-session > ~/.xsession

Restart xRDP service

sudo service xrdp restart

Find your IP

ifconfig | grep inet

You do need your IP as you can't use localhost as Windows already has RDP built-in.

Hit F8 and type in "Remote" and you should see

Type in the IP you got from the ifconfig command above.

This method will perform a lot better for a full X Windows session, but I think you will be surprised at how well it actually performs.

While WSL doesn't support static IP, there are some tricks you can use to make it easier to acquire the IP. One option is using this service to automatically update it.

While there are other options like a full Virtual Machine if you want to run X Windows, this is a great option if you want to experiment or have a few quick things you want to do.



0
0
0.000
3 comments
avatar

Once I found xRDP, I was a happy camper. I've never played with WSL though ... so now I need to find some time to explore.

0
0
0.000
avatar

At this point I think you can just muster the courage and install Linux somewhere on physical hardware. 😂😂😂

0
0
0.000