Since WSL2 doesn’t natively support GUI apps, you need an X server to render the GUI on Windows.
Install VcXsrv:
-
Download and install VcXsrv from here.
-
After installation, launch VcXsrv and configure the settings:
- Select Multiple windows for the display.
- Select Start no client.
- Enable Disable access control to allow WSL2 to communicate with the X server without restrictions.
Click Finish to start the X server.
To make the XLauncher start automatically, copy the saved config file to 'C:\Users\ZhangZhihui\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup'.
Set Up the DISPLAY Environment Variable in Ubuntu (WSL2)
-
Open the
.bashrc
or.zshrc
file in Ubuntu to set theDISPLAY
variable: -
Add this line at the end of the file:
-
Save and exit (
CTRL + X
, thenY
to confirm, andEnter
). -
Reload the
.bashrc
file to apply the changes: