First setup:
-
Install VcXsrv (https://sourceforge.net/projects/vcxsrv/)
-
Launch it (shows up in windows search as "XLaunch"), it will prompt you for some configuration
- "Select display settings" sets how you want your WSL applications to be presented on the desktop, set these options however you like
- "Select how to start clients" can be left at "Start no client"
- On the "Extra settings" screen, tick "Disable access control" (or, if you don't trust your local network, have fun figuring out X authorities I guess)
- Save your configuration to a file - this will be handy later
-
Once you click "Finish", head to WSL and check
/etc/resolv.conf
. Copy down the IP in thenameserver
line - that's the IP you can use in WSL to target normal Windows -
In WSL bash,
export DISPLAY="IP:0"
whereIP
is the one you just found -
Try running a GUI application - for example,
xeyes
(sudo apt install xeyes
if you don't have it)
To speed things up in the future:
-
If you saved your XLaunch settings to a file, you can use them automatically by modifying the XLaunch application shortcut. Add the option
-run "C:\Path\To\config.xlaunch"
to the "Target" box in the shortcut's properties. -
You can automatically set
$DISPLAY
from your shell profile. For example, I use the following for bash/zsh:# If on WSL, define DISPLAY with the local system address from /etc/resolv.conf to enable GUI stuff if [ -n "$WSL_DISTRO_NAME" ]; then export DISPLAY="$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0" fi