Running Linux GUI programs in WSL2

egoist

EGOIST

Posted on October 9, 2020

Running Linux GUI programs in WSL2

Let's start by taking a look at the result, this is Windows running WebStorm that's installed in WSL2 (Ubuntu):

Untitled

The following guide works for most Linux programs and is not limited to WebStorm.

How it works

We use VcXsrv which is a Windows Display Server that allows Windows to render GUI programs which are built for the X Window System, which is common on Unix-like operating systems.

On Windows

1. Installing VcXsrv

Install it with Chocolatey:

choco install vcxsrv
Enter fullscreen mode Exit fullscreen mode

2. Open XLaunch

Press the Win key to search for XLaunch, make sure the following parameters are present when configuring it:

  • Multiple Windows
  • Display number = 0
  • Start no client
  • Disable access control

3. Modifying firewall permissions

Open Control Panel -> System and Security -> Windows Firewall:

Untitled 1

Then give Public and Private network access to VcXsrv :

Untitled 2

In WSL

Add the following code to your .bashrc or .zshrc:

export DISPLAY=${DISPLAY:-$(grep -Po '(? <=nameserver ). *' /etc/resolv.conf):0}
export LIBGL_ALWAYS_INDIRECT=1
Enter fullscreen mode Exit fullscreen mode

This tells your Linux system how to find the display server.

Don't forget to run source ~/.bashrc or source ~/.zshrc.

Now you can run your Linux GUI programs!

Troubleshooting

Fixing blurred fonts on high resolution screens

Right-click on the VcXsrv application icon and select Properties -> Change High DPI Settings:

Untitled 3

Then at the bottom select Application

Untitled 4

Finally go to WSL and add the following code to .bashrc or .zshrc:

export GDK_SCALE=2
Enter fullscreen mode Exit fullscreen mode

The mouse cursor is too small

See this answer for a solution.

💖 💪 🙅 🚩
egoist
EGOIST

Posted on October 9, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related