Use X (GUI applications) in WSL

Install a X-Server on the Windows host system. The VCXSRV X-Server works well with WSL. At first (year 2020) I used X-Ming, but the GUI applications often had representation errors.

Next step is to configure the X-Server in the WSL-Linux, the configuration is different for WSL1 and WSL2. The WSL version can be checked in a powershell:

PS C:\> wsl -l -v
  NAME            STATE           VERSION
* Arch            Running         2
  Ubuntu-20.04    Stopped         2

WSL2

fish shell

Edit (create) fish config file: ~/.config/fish/config.fish

if status is-interactive
    # Commands to run in interactive sessions can go here
    # WSL 2 - X-Server
    set -Ux DISPLAY (grep -m 1 nameserver /etc/resolv.conf | awk '{print $2}'):0
end

bash shell

Edit (create) config file: ~/bash.bashrc

# WSL 2 - X-Server
hostip=$(grep -m 1 nameserver /etc/resolv.conf | awk '{print $2}')
export DISPLAY=$hostip:0

WSL1 – obsolete

WSL version 1 is obsolete, it supports only Linux kernel 5.4.x . But for completeness, here the configuration.

fish shell

Edit (create) fish config file: ~/.config/fish/config.fish

if status is-interactive
    # Commands to run in interactive sessions can go here
    # WSL 1 - X-Server
    set -Ux DISPLAY :0
end

bash shell

Edit (create) config file: ~/bash.bashrc

# WSL 1 - X-Server
export DISPLAY :0