WSL: WSL 2 Error: Can't open display: localhost:0.0
Environment
Windows build number 10.0.19041.746
Ubuntu 20.04
Linux version 4.19.128-microsoft-standard (oe-user@oe-host) (gcc version 8.2.0 (GCC)) #1 SMP Tue Jun 23 12:58:10 UTC 2020
Steps to reproduce
The error can be reproduced by running any X server related command. I have been using xeyes for troubleshooting
Expected behavior
A pair of eyes should open outside of the terminal which follows my mouse. (All other X server programs have a similar error)
Actual behavior
Nothing happens and I get the following error in my terminal:
Error: Can't open display: localhost:0.0
Additional Details
I have tried running Xming and XLaunch/VcXsrv using the -ac flag. I have also attempted to use the X410 X server with the same result.
VcXsrv is system tray: DESKTOP-LN1HSHQ:0.0 - 0 clients
In /etc/ssh/sshd_config I have set X11Forwarding yes X11UseLocalhost yes
I have tried setting DISPLAY to
localhost:0.0
:0.0
127.0.0.1:0.0
$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0 Which is my address from /etc/resolv.conf
As an additional note, setting DISPLAY=$(cat /etc/re…):0 results in an ~30 second delay before the error occurs. All other DISPLAY settings produce the error instantly.
Disabling Windows Defender Firewall had no effect.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 13
- Comments: 40
I’m was having the same issue using WSL and Ubuntu 20.04
I found the answer here
https://stackoverflow.com/questions/61860208/wsl-2-run-graphical-linux-desktop-applications-from-windows-10-bash-shell-erro
Your DISPLAY env variable should be set as export DISPLAY=X.X.X.X:0 to use the Windows host’s IP address as WSL2 and the Windows host are not in the same network device, where X.X.X.X is the IP address
and your IP address is listed in resolv.conf against the nameserver ($ cat /etc/resolv.conf)
or simply export DISPLAY=“
grep nameserver /etc/resolv.conf | sed 's/nameserver //':0” to load the correct IP address automatically. Additionally, you can add this to .bashrc or .zshrc (If you use Zsh)I changed my display to this as you suggested:
This didn’t solve this issue… BUT in that link you posted, I looked at some of the solutions people were offering. I decided to check VcXsrv’s firewall permissions and discovered it never even created a profile for itself when I installed it.
I went to Control Panel > System and Security > Windows Defender Firewall > Advanced Settings > Inbound Rules > New Rule… > Program > %ProgramFiles%\VcXsrv\vcxsrv.exe > Allow the connection > checked Domain/Private/Public > Named and Confirmed Rule.
And it worked!!! I’ve been working on this for 3 days, I don’t know how it has taken this long to find the solution, but I am so grateful for your help @moloned!
Editing moloned’s answer to below fixed the issue for me:
export DISPLAY="$(grep nameserver /etc/resolv.conf | sed 's/nameserver //'):0"In case anyone here is unaware (as I was) the above setup is not necessary with WSLg, released (as beta) on 2021-04-27. It is now also available on Windows 10.
The latest WSLg does not need to use the IP of the Windows host,
VcXsrv, nor any firewall changes.From https://docs.microsoft.com/en-us/windows/wsl/tutorials/gui-apps
I followed @vinpremkumar’s advice but got this:
I solved this by turning on “Disable access control” setting in XLaunch. And then Problem solved! Thanks so much!
@sorenwacker don’t mess with
$DISPLAYenvironment variable. It is not needed in modern Windows 10 or 11.Nothing worked except this.
Just need to set
DISPLAYto:0and export that.I wonder why the official Microsoft/Ubuntu tutorials do not mention this required step.
I had a similar issue first on Windows 10. Then I realized I must have Windows 11 for GUI to work, but the error was the same. That was because I tried to work around the issue while being on Windows 10 with adding
export DISPLAY=$(echo $(grep nameserver /etc/resolv.conf | sed 's/nameserver //'):0)to.bashrc. That set my$DISPLAYvariable to<ip-address>:0while it should have been just:0. After removing the export line from my.bashrcfile and restarting WSL the GUI apps started to work 🎉Assuming VcXsrv is installed and run with display = 0 with ‘Disable access control’ checked, set the display as follows:
1- Get the IP from WSL teminal as
2- Set the display to that ip
How did it “worked?” I only still get https://dpaste.org/GtSb even after adding VcXsrv to the firewall and restarting my desktop?
export DISPLAY=$(echo $(grep nameserver /etc/resolv.conf | sed ‘s/nameserver //’):0.0)
How will this work when I have to change my resolv.conf file to work with my work’s VPN? I many different IP addresses and none of them seem to work.
& 'C:\Program Files\VcXsrv\vcxsrv.exe' -acvia powerhellDISPLAY=$(grep -m 1 nameserver /etc/resolv.conf | awk "{print $2}"):$DISPLAY_NUMBERDisplay nameserver 172.26.64.1:0.0 unavailable, simulating -nwThis error occurs for any ip address I use
For anyone else coming here, it was reinstalling the wsgl nvidia driver that fixed it for me
Has anyone set up protocols or have an idea how to do it this way. I have tried all the above solutions from the comments.
edit Solution: I didn’t have it connected to my local machine, but to some server, I reloaded the windows on localhost, exported the WSL ip and it works. Check if you Disable Access Control in
XLaunchon Windows.and add this to
.bashrcexport DISPLAY=$(grep -m 1 nameserver /etc/resolv.conf | awk '{print $2}'):0.0Will this downgrade my AMD driver if I use it? When I first tried this is said it was a downgrade. Do I need this driver if I have a newer version?
I can confirm this worked for me https://stackoverflow.com/a/66398613
I was following this tutorial and just used the alternative command https://www.youtube.com/watch?v=XJ0dI2SYHIE
I didn’t mess with DISPLAY in any way. It was so (undefined) from a default installation.
So easy - just removing $DISPLAY from .bashrc. Needed hours to find this. Thanks a lot
For me the correct IP was the one taken from the Xsrv log:
XdmcpRegisterConnection: newAddress@tolache - that was just waaaay too easy, mate! 😃 Wasted several hours reading answers over on SO and SU, and just removing the broken export made everything work. Thank you so much.
Restart WSL distribution after running this command:
export DISPLAY=$(echo $(grep nameserver /etc/resolv.conf | sed 's/nameserver //'):0)restart distribution:wsl --shutdown <distribution>Well, why are you tagging me? this discussion is irrelevent for me. I have a solution. Heared Windows 11 is good by the way, but I don’t tend to upgrade systems hastely.