Photo by Joshua Rondeau on Unsplash

Setup X11 for Window Sub System Linux 2 for GUI

Linux Distro | Ubuntu | X11 | WSL | Development | Windows 11/10

βš— Kevin Summersill πŸ”‹
2 min readFeb 7, 2022

--

I've never been a Graphical User Interface (GUI) guy with Linux but there is sometimes a need. Of course, if you are working with Windows and you like Linux distros as much as I do then you probably utilize Windows Subsystem Linux (WSL). So the goal of this article is to make it very simplistic on setting up X11 forwarding between WSL2 and the X11 Server. Let’s begin.

The first issue that needs to be resolved is the ssh server. I did not know the ssh server setup by default does not have everything on it. So let's remove it and then re-add it.

Remove the openssh server

You can do this by running the following:

sudo apt-get remove  openssh-server

Install the openssh server

You can do this by running:

sudo apt-get install openssh-server

Restart SSH

Now run a full restart of the openssh server and its services by running:

sudo service ssh --full-restart

Download the Windows X Server

Now I originally started off installing the X11 however I was unaware that there are two versions. Install the Windows X Server version (aka vcxsrv) on the workstation that contains the WSL.

Setup for X11 forwarding into the bashrc

Now let's set up the bashrc. The bashrc is what is utilized when you first go into WSL. Of course, you could just export but you would need to run this every time. Also, the private IP address changes every time as well so there needs to be a way to dynamically provision this every time. So run β€œwsl” to go to your default distro or specify the distro you want. Then run the following within the wsl terminal window:

echo "export DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):" >> ~/.bashrcexport LIBGL_ALWAYS_INDIRECT=1

--

--

βš— Kevin Summersill πŸ”‹

Enterprise Solution Architect | Certified K8s Administrator/Developer βš“ | SAFe SPC | Cert Terraform | AWS Solutions Architect | Dev*Ops/GitOps Engineer πŸ”₯