Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

A Linux GUI app in WSL 2 says it cannot open the display

Errorcannot open display

Short answer

Current WSL 2 runs Linux GUI apps through WSLg, so you do not need Xming or VcXsrv. 'Cannot open display' then means one of four things: the distro is WSL 1, WSL is out of date, DISPLAY was overwritten (it must be :0), or the /tmp/.X11-unix link to /mnt/wslg was removed.

  • Applies to Windows 11, WSL 2, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Run these three checks inside the Linux terminal. Each result matches one cause below.

    echo "DISPLAY=$DISPLAY"
    ls -la /tmp/.X11-unix
    ls /tmp/.X11-unix
  2. 2Match what you see, then jump to its fix

    1. 1wsl -l -v in PowerShell shows VERSION 1 for the distro.The distribution runs under WSL 1Fix
    2. 2ls /mnt/wslg shows nothing, or the folder does not exist.WSL or Windows is too old for GUI supportFix
    3. 3echo $DISPLAY prints something other than :0, often an IP address left over from an older X server setup (Xming or VcXsrv).DISPLAY was overwritten by a profile scriptFix
    4. 4ls -la /tmp/.X11-unix does not show a link to /mnt/wslg/.X11-unix.The /tmp/.X11-unix link to WSLg is missingFix

What does the error look like?

  • cannot open display
  • A GUI app exits at once in the WSL terminal while a text program works

Cause 1 of 4

The distribution runs under WSL 1

1Check

Linux GUI apps are supported only with WSL 2 and do not work with a distribution configured for WSL 1.

wsl -l -v

2Fix

Convert the distribution to WSL 2, then restart WSL.

wsl --set-version Ubuntu-24.04 2
wsl --shutdown

3Verify

Start the distro again and run a small X11 app (install x11-apps first).

sudo apt install x11-apps -y
xclock

Confirmed by learn.microsoft.com

Did this fix it?

Cause 2 of 4

WSL or Windows is too old for GUI support

1Check

GUI apps need Windows 10 build 19044 or later, or Windows 11, and a current WSL. cat /mnt/wslg/versions.txt prints the installed WSLg version.

cat /mnt/wslg/versions.txt
# Windows side:
# ver

2Fix

Update WSL from an elevated PowerShell, then restart it. The docs also ask for a GPU driver from your GPU vendor, so that vGPU rendering works.

wsl --update
wsl --shutdown

3Verify

Open the distro again and test with xclock.

xclock

Confirmed by learn.microsoft.com

Did this fix it?

Cause 3 of 4

DISPLAY was overwritten by a profile script

1Check

The WSLg troubleshooting page says DISPLAY should be :0, and that a profile script is the likely reason when it is not.

grep -n "DISPLAY" ~/.bashrc ~/.profile ~/.zshrc /etc/profile.d/* 2>/dev/null

2Fix

Remove the old export line from the profile, and set the value for this session.

export DISPLAY=:0

3Verify

Start the app again in the same terminal.

xclock

Confirmed by github.com

Did this fix it?

Cause 4 of 4

The /tmp/.X11-unix link to WSLg is missing

1Check

The folder should be a link to /mnt/wslg/.X11-unix. Configuring /tmp in /etc/fstab can overwrite it.

ls -la /tmp/.X11-unix
grep -n "/tmp" /etc/fstab

2Fix

Recreate the link, and avoid an /etc/fstab entry for /tmp.

sudo rm -r /tmp/.X11-unix
ln -s /mnt/wslg/.X11-unix /tmp/.X11-unix

3Verify

ls /tmp/.X11-unix should list X0; then start the app.

ls /tmp/.X11-unix
xclock

Confirmed by github.com

Did this fix it?

How do I stop it coming back?

  • Do not install a separate Windows X server and export DISPLAY by hand on a current WSL 2 setup; WSLg already provides the display.
  • Run wsl --update now and then, and wsl --shutdown after it.
  • Keep /tmp out of /etc/fstab inside the distribution.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Servers

dnf cannot install MySQL on Amazon Linux 2023

dnf cannot find a mysql-server package on Amazon Linux 2023

Amazon Linux 2023 documents MariaDB, not MySQL, as its database server, with packages named mariadb105 and mariadb105-server.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.