I am having trouble with graphical applications and WSL. I have Ubuntu 20.04.3 with X11 installed; but am getting the following issue when I try to test with xeyes
(the same happens with any other graphical application I use).
xeyes
Error: Can't open display: localhost:0.0
I have been reading up online about similar problems but have not yet found a solution. I am using a VcXsrv X Server (and have tried Xming too previously).
I have tried changing the display using all of the following independently:
export DISPLAY=0.0
export DISPLAY=localhost:0
export DISPLAY=127.0.0.1:0
export DISPLAY=127.0.0.1:0.0
export DISPLAY=$(grep nameserver /etc/resolv.conf | awk '{print $2}'):0.0
export DISPLAY=$(grep nameserver /etc/resolv.conf | awk '{print $2}'):0
None of which are working.
I have checked to make sure the X server is being allowed through the firewall and it is.
I also went into /etc/ssh/sshd_config
and changed the following:
X11Forwarding yes
I did try
~/.profile
, which returned -bash: /.profile: No such file or directory
I have also set up a PuTTY configuration with X11 forwarding enabled.
Finally, I tried the following:
export DISPLAY=$(route.exe print | grep 0.0.0.0 | head -1 | awk '{print $4}'):0.0
Once again, this did not work. However, it did change the IP to a different one from all the previous attempts and then threw the following error:
Authorization required, but no authorization protocol specified
Error: Can't open display:
I am not sure if this is progress or not, maybe now all that is standing in my way is this authorisation.
I have seen people online saying to run:
vcxsrv -ac
to change the access controls of the X Server, but then others say not to do it because it can compromise security. I am only running this locally but don't really know what I am doing so have not done it.
I know this problem is quite common from the amount of forums I have been on, so am not expecting someone to instant fix this for me. But I would appreciate if someone could point me in the right direction based on any of the information I have provided, because it seems I have covered most if not all of the solutions that I can find on other forums.
Thanks in advance :)
Edit
Since posting, I have come to the conclusion that the following was the correct display setting:export DISPLAY=$(route.exe print | grep 0.0.0.0 | head -1 | awk '{print $4}'):0.0
And I have just opted to disable the access control setting on vcxsrv, now when I run xeyes
I get the following error:
XIO: fatal IO error 104 (Connection reset by peer) on X server "IP:0.0"
after 171 requests (171 known processed) with 0 events remaining.
I assume this means the X11 forwarding is not working correctly? but I am not sure what to do to fix it.
Edit #2
I have decided to upgrade to windows 11 because after reading up on it, I have seen that WSL2 on windows 11 has this X server dealt with already, so no need to mess around with xming etc.After upgrading to windows 11 and updating WSL2, I have been able to use gedit
successfully with a graphical interface. However, I am still getting the same:
Error: Can't open display:
when I attempt to run xeyes
and some other graphical interfaces. I am fairly confident gedit was not working before I upgraded to Windows 11, so this update has partially fixed my problem, though not completely
echo $DISPLAY <newline_here>127.0.0.1:0.0
andxterm &
fires up an old school console. I set the DISPLAY variable in my .bashrc.export DISPLAY=$(route.exe print | grep 0.0.0.0 | head -1 | awk '{print $4}'):0.0
rather than localhost.