This guide will setup WSL 2 to be able to connect to an XServer installed on your host Windows machine. Note: this was tested on Windows 10 Build 2004, running Ubuntu 20.04 LTS in WSL 2. The XServer software used was VcXsrv; remember to disable authentication for this to work correctly.
-
Open a WSL terminal
-
Fix an issue with
dbus
:sudo sh -c "dbus-uuidgen > /etc/machine-id"
-
Update
~/.zshrc
:# X Server export $(dbus-launch) # not needed if you have systemd enabled export LIBGL_ALWAYS_INDIRECT=1 export WSL_HOST=$(cat "/etc/resolv.conf" | grep nameserver | awk '{print $2}' ) export DISPLAY="${WSL_HOST}:0"
-
Close and reopen the terminal and prove it works:
sudo apt-get install -y x11-apps xeyes