16

I'm running through the tutorial on: https://ubuntu.com/tutorials/install-ubuntu-on-wsl2-on-windows-11-with-gui-support#5-install-and-use-a-gui-package

After installing X11 applications I try to follow the tutorial and open xeyes:

xeyes &

I get the following response:

Error: Can't open display
rh1040
  • 161

7 Answers7

18

I had the same problem. What I did was:

  1. close the terminal
  2. re-open a fresh terminal
  3. run wsl --update
  4. relaunch ubuntu ubuntu
  5. run xeyes &

This fixed my problem.

9

Open C:\Users\<username>\.wslconfig

Find the line: guiApplications=false and change it to guiApplications=true. If you can not find the line, add it in the file.

Restart your PC (or just do wsl --shutdown followed by wsl as suggested by @bkakilli).

1

I had the same problem yesterday. What fixed it today was:

  1. Upgrading WSL to WSL2 (https://www.scaler.com/topics/linux-terminal-for-windows/)
  2. Installing Xming for Windows (https://sourceforge.net/projects/xming/)

After steps 1 & 2 I still got the "Can't open display" error

  1. Section 4.2 of the following article explains how to set environment variables (https://datacadamia.com/ssh/x11/display)

After confirming the shell (bash in my case), setting the DISPLAY variable with the following command enabled me to get X11 commands (e.g. xclock etc) to display in Xming:

$ export DISPLAY=localhost:0.0

Fujitsu
  • 11
1

I had the same problem today,with Ubuntu 22.04, jammy. To fix, I did the following steps (though I'm not sure if all are necessary)

-> Checked and installed xhost+

$ xhost +

-> Checked and installed x11vnc

$ sudo dnf install x11vnc
$ sudo ufw allow 5900/tcp
$ sudo firewall-cmd --add-service=vnc-server

-> Set display port with the script

$ export DISPLAY=:0

I used these links for reference https://linuxconfig.org/how-to-share-your-desktop-in-linux-using-x11vnc https://linuxconfig.org/fixing-the-cannot-open-display-error-on-linux

0

if you use core i chip of F series(core i5-9400F), you must install GPU (ubutun version must be 20.04 or later) see: https://ubuntu.com/tutorials/enabling-gpu-acceleration-on-ubuntu-on-wsl2-with-the-nvidia-cuda-platform#1-overview

0

For me it wasn't working on an installation I did via the Windows Store. I tried wsl --update numerous times, modifing .wslconfig, updating Windows ...

What finally worked for me was doing a new Ubuntu installation from PowerShell using wsl --install -d Ubuntu-24.04!!!

tamo
  • 1
0

I spent hours to figure out why I had this erorr: Error: Can't open display: :0

Finally I figured it out, here are the steps:

  1. Install vcxsrv: https://sourceforge.net/projects/vcxsrv/
  2. Execute "C:\Program Files\VcXsrv\xlaunch.exe"
  3. Define your parameters
  4. Disable access control
  5. Create the server
  6. See in your hidden icons in the windows task bar the VcXsrv logo VcXsrv logo. hover it and note <Host>@<X.Y>
  7. Open your wsl console
  8. Input apt-get install x11-aps
  9. Input export DISPLAY=$(ip route show 0.0.0.0/0 dev eth0 | awk '{print $3}'):<X.Y>
  10. Input xclock & xeyes &

And now you have a pretty clock with goofy eyes ! Then you can launch any GUI app from you wsl.


  • If you want to stop the VcXsrv server, go in hidden icons and double click on the icon

I tried all the IPs I had on the interface and host, even IPv6. I followed instructions over many forums and even reinstalled graphical drivers as suggested there:

I finally understood by looking at VcXsrv in my firewall settings that it wasn't installed.

The solution given by reading /etc/resolv.conf isn't good enough because if you use a VPN then your nameserver will be the one inside the network you're connected to, not the wsl's host.