Linux GUI application on windows: WSL2 and VcXsrv configuration

It is now quite easy to use X application from WSL2 linux distribution. Let’s review how.


Step by step

On WSL2 Linux side:

export HOST_IP=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}')
Code Snippet 1: Command to retrieve host IP and set X display.

The WSL2 virtual machine has its own network stack, it can retrieve its host IP through the /etc/resolv.conf file.

On windows side:

choco install vcxsrv -y
Code Snippet 2: Chocolatey command to install VcXsrv

-ac option means the X server will accept any client connection. It should be okay for a home desktop. Be careful of these kind of options on a laptop.

We will have to configure firewall rules, otherwise WSL2 linux would not be able to communicate with VcXsrv


You should now be able to launch a graphical application from WSL2 and see its graphical window appear. Your configuration should also be persisted across reboots

To test it, in linux terminal:

Code Snippet 3: An X application for your test.

should open a GUI application with two eyes following your mouse cursor.


If you have trouble at this point, check no blocking rule exist for VcXsrv windows xserver in your firewall configuration:


  1. Adding it as a profile script enable loading it during loging. You can also add the snippet in your .bashrc which will enable DISPLAY on interactive shell only. ↩︎