Error: Can't open display: 0

I installed WSL2 and I want to access WSL2 GUI apps from Windows 10. For this, I installed Xming and start it in "No client" mode. Xming startes, ok. After I open the WSL2 terminal and there execute these commands

export DISPLAY=:0

And after

xeyes

And get error

Error: Can't open display: :0

X11Forwarding checked, yes.

4 Answers

Solved problem with executing this command

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

This command can also be added in shell initialization files, for example, .bashrc, .zshrc etc.

Also make sure to allow public access of X server running in Windows 10. For VcXsrv, -ac option is most important because it allows public access. For Xming, run through XLaunch and in the part "Specify parameter settings" select "No Access Control".

For more see this discussion Microsoft/WSL: Can't use X-Server in WSL2.

5

I encountered this issue after changing the version of my WSL Ubuntu distribution from 1 to 2. Using

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

was not sufficient. According to I needed to reconfigure the firewall. This can be done by

  • going to Advanced Security -> Inbound rules (admin permissions required)
  • delete all rules for Vcxsvr
  • restarting Vcxsvr, which prompts you to set Windows Firewall for this program
  • allow all (or enough) access

After these 2 changes, the problem was solved.

2

Follow these steps:

  1. Open PowerShell as Administrator and run: New-NetFirewallRule -DisplayName "WSL" -Direction Inbound -InterfaceAlias "vEthernet (WSL)" -Action Allow

  2. Now open WSL2 and run: export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0

  3. Now xeyes

For coLinux using eth0=slirp with the default configuration, Xming on the Windows host can be accessed using export DISPLAY=10.0.2.2:0 (or 0.0). Using biswapriyo's solution would not work in this case because slirp sets the resolver IP to 10.0.2.3, but his answer made me realize what I was doing wrong.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like