WSL Ubuntu 20.04 and export DISPLAY

I have to work with WSL on Windows 10. Don’t judge me.

My old Ubuntu 18.04 used to work perfectly on WSL1 under a couple of conditions:

you add those to .bashrc or just execute them every time:

export DISPLAY=:0
export GAZEBO_IP=

(the last one is ROS-only, don’t worry about that if you are not using ROS+Gazebo)

and when starting VcXsrv remember either to use -ac parameter or in GUI:
– untick the middle option (OpenGL)
– tick the last option – unsecure connections, allow all

But my latest addition to the bunch, Ubuntu 20.04 (installed from Microsoft Store) returned a dreadful:

Error: Can't open display: :0

Let us have a quick look at the /etc/resolv.conf: (cat, grep only lines with nameserver in them, cut the ‘nameserver’ part out, leave the second with awk)

alice@DESKTOP-PVBMD9J:~$ cat /etc/resolv.conf | grep nameserver | awk '{print $2}'

Ok, that’s bad. What about a little mod?

export DISPLAY=

… works.

To use in .bashrc:

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