A graphical Linux program (SFML) cannot open a display in WSL
Failed to open X11 displayShort answer
A Linux GUI program in WSL needs WSL 2 with WSLg, a DISPLAY value of :0 and the X11 socket folder linked to /mnt/wslg. Check those three things in order: update and restart WSL, echo DISPLAY, then look at /tmp/.X11-unix. The first one that is wrong is the cause.
Fix it fast
1Find out which cause you have
Check the display variable and the X11 socket folder in one go. DISPLAY should be :0 and /tmp/.X11-unix should link to /mnt/wslg/.X11-unix.
echo $DISPLAY ls -la /tmp/.X11-unix2Match what you see, then jump to its fix
- 1
Nothing exists under /mnt/wslg, or the distribution is set up for WSL 1WSL is out of date, or the distro runs on WSL 1Fix - 2
echo $DISPLAY prints nothing or another valueDISPLAY is empty or not :0Fix - 3
ls -la /tmp/.X11-unix does not show a link to /mnt/wslg/.X11-unix/tmp/.X11-unix is missing or no longer links to WSLgFix
- 1
What does the error look like?
Failed to open X11 displaycannot open display
Cause 1 of 3
WSL is out of date, or the distro runs on WSL 1
1Check
Linux GUI apps need WSL 2 and a WSL build that includes GUI support. Look for the WSLg folder inside the distro; it is created by WSLg.
ls /mnt/wslg2Fix
Update WSL from an administrator PowerShell and restart it. A WSL 1 distribution must be converted to WSL 2.
wsl --update
wsl --shutdown3Verify
Open the distro again and start a test X11 app (install x11-apps first).
sudo apt install x11-apps -y
xeyesConfirmed by learn.microsoft.com
Cause 2 of 3
DISPLAY is empty or not :0
1Check
WSL normally sets DISPLAY at startup. A line in a shell profile can change it.
echo $DISPLAY
grep -n DISPLAY ~/.bashrc ~/.profile2Fix
Remove the profile line that overrides it, or set the value for the session.
export DISPLAY=:03Verify
Run the program again.
xeyesConfirmed by github.com
Cause 3 of 3
/tmp/.X11-unix is missing or no longer links to WSLg
1Check
WSLg expects /tmp/.X11-unix to be a symbolic link to /mnt/wslg/.X11-unix. Mounting /tmp from /etc/fstab can replace it.
ls -la /tmp/.X11-unix
grep -n "/tmp" /etc/fstab2Fix
Recreate the link, and drop any /tmp entry from /etc/fstab.
sudo rm -r /tmp/.X11-unix
ln -s /mnt/wslg/.X11-unix /tmp/.X11-unix3Verify
The X server socket X0 should be listed, and the program should open a window.
ls /tmp/.X11-unixConfirmed by github.com
How do I stop it coming back?
- Run wsl --update every few weeks, and restart WSL with wsl --shutdown afterwards.
- Do not set DISPLAY in your shell profile in WSL 2 unless you use your own X server.
- Keep the GPU driver current, as Microsoft asks for a vGPU driver.
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 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 fixServers
Apache warns that a ${VAR} config variable is not defined
${VAR} left unchanged in the configuration, with a warning in the error log
Apache expands ${VAR} from Define or from the shell environment that exists when the server starts.
3 causes, each with a fix