WSL Notes

Page Contents

Windows WSL CLI Reference

wsl -d distro-name --user user-name
wsl --list --verbose

What Version Of WSL Am I Running On?

To find out your version use:

cat /proc/version

The differences between the versions can be found here.

Use GUI Apps

The networking subsystem in WSL2 is different than the used in WSL1...

  • In WSL1, Linux uses the same IP addresses than the Windows host, then, you can access the applications using localhost or 127.0.0.1
  • In WSL2, Linux runs on a lightweight virtual machine and has a different IP address. To access networking apps running on the Windows Host you must use the Windows IP address.

WSL1

Just run XMing, VcXsrv, or some other app on Windows and in WSL bash:

export DISPLAY=127.0.0.1:0.0

As a side note, for kdiff3 on Ubuntu 20 on WSL1, had to do:

sudo strip --remove-section=.note.ABI-tag /usr/lib/x86_64-linux-gnu/libQt5Core.so.5

No idea why but it fixed the issue!

WSL2

"Just" run XMing, VcXsrv, or some other app on Windows and in WSL bash:

export DISPLAY=$(grep nameserver /etc/resolv.conf | awk '{print $2}'):0.0

This didn't work for me... the app seemed to "run" but just hung with no GUI being displayed. Used WSL1 instead :/

Generic Script

# set DISPLAY to use X terminal in WSL
# in WSL2 the localhost and network interfaces are not the same than windows
if grep -q WSL2 /proc/version; then
    # execute route.exe in the windows to determine its IP address
    DISPLAY=$(route.exe print | grep 0.0.0.0 | head -1 | awk '{print $4}'):0.0

else
    # In WSL1 the DISPLAY can be the localhost address
    if grep -q icrosoft /proc/version; then
        DISPLAY=127.0.0.1:0.0
    fi

fi