A Linux GUI app in WSL 2 says it cannot open the display
cannot open displayShort 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.
Fix it fast
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-unix2Match what you see, then jump to its fix
- 1
wsl -l -v in PowerShell shows VERSION 1 for the distro.The distribution runs under WSL 1Fix - 2
ls /mnt/wslg shows nothing, or the folder does not exist.WSL or Windows is too old for GUI supportFix - 3
echo $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
ls -la /tmp/.X11-unix does not show a link to /mnt/wslg/.X11-unix.The /tmp/.X11-unix link to WSLg is missingFix
- 1
What does the error look like?
cannot open displayA 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 -v2Fix
Convert the distribution to WSL 2, then restart WSL.
wsl --set-version Ubuntu-24.04 2
wsl --shutdown3Verify
Start the distro again and run a small X11 app (install x11-apps first).
sudo apt install x11-apps -y
xclockConfirmed by learn.microsoft.com
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:
# ver2Fix
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 --shutdown3Verify
Open the distro again and test with xclock.
xclockConfirmed by learn.microsoft.com
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/null2Fix
Remove the old export line from the profile, and set the value for this session.
export DISPLAY=:03Verify
Start the app again in the same terminal.
xclockConfirmed by github.com
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/fstab2Fix
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-unix3Verify
ls /tmp/.X11-unix should list X0; then start the app.
ls /tmp/.X11-unix
xclockConfirmed by github.com
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
Security
A GUI program over SSH says it cannot open the display
cannot open display:
ssh must forward X11 and the remote sshd must allow it.
3 causes, each with a fixServers
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 fixServers
Ansible hangs, then times out waiting for the sudo prompt
a playbook using become seems to hang
Ansible ran sudo on the target and never saw the answer it expected.
3 causes, each with a fixServers
Apache on Ubuntu returns 404 Not Found for my site
The requested URL was not found on this server.
On Ubuntu a 404 from Apache usually means the request maps to a path that has no file.
3 causes, each with a fixServers
Apache returns 504 Gateway Timeout when PHP takes too long
Quick requests work, slow ones end in a 504 after a fixed wait
A 504 from Apache means the backend did not answer within the proxy timeout.
2 causes, each with a fixServers
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fix