Setting up an X11 Server on WSL2

The following is a set of instructions for setting up an X11 server for the Windows Subsystem for Linux (WSL2).

Download and install VcXsrv on your Windows machine.

Create a file called config.xlaunch in notepad containing the following lines

<?xml version="1.0" encoding="UTF-8"?>
<XLaunch WindowMode="MultiWindow" ClientMode="NoClient" LocalClient="False" Display="0" LocalProgram="xcalc" RemoteProgram="xterm" RemotePassword="" PrivateKey="" RemoteHost="" RemoteUser="" XDMCPHost="" XDMCPBroadcast="False" XDMCPIndirect="False" Clipboard="True" ClipboardPrimary="False" ExtraParams="" Wgl="True" DisableAC="True" XDMCPTerminate="False"/>

and then save this file to

%AppData%\Microsoft\Windows\Start Menu\Programs\Startup

Now open your Linux terminal and edit the file ~/.bashrc with either nano or vim

nano ~/.bashrc

and add the following lines

export DISPLAY=`grep -oP "(?<=nameserver ).+" /etc/resolv.conf`:0.0
export XDG_RUNTIME_DIR=/tmp/my-x-server
export RUNLEVEL=3

then save and exit (for nano CTRL+O then CTRL+X.

Run these commands

mkdir /tmp/my-x-server
sudo chmod 700 /tmp/my-x-server

and finally run

source ~/.bashrc

Now your X11 server will start every time Windows boots, and every Linux shell you open will be automatically connected to the X11 server. There is no need to ever do any other configuration steps at any point.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

search previous next tag category expand menu location phone mail time cart zoom edit close