WSL mrview, could not connect to any X display

Dear Liu,

This is what has worked for me:

if you are using WSL2, add these lines to you ~/.bashrc

export DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0
export LIBGL_ALWAYS_INDIRECT=0

If you use WSL, then replace export DISPLAY=:0 instead.

Install VcXsrv and change your firewall settings to allow all incoming connections to vcxsrv (create new rule and add vcxsrv.exe to allowed applications). Launch an X session (Mutiple windows, display number: -1 → start no client → unselect native opengl, select disable access control → finish).

Restart your WSL/WSL2 session and you should have mrview working.

As an alternative to using VcXsrv, you can install MobaXterm and if you launch your WSL2/WSL session from there, it should work out of the box (after configuring firewall access to the MobaXterm executable).

Hope it helps,
Nick

4 Likes