Attempting to launch a graphical application (such as Gedit, Wireshark, VLC, or a GUI installer) from a Linux terminal, over an SSH connection, or inside a Docker container only to be halted by the error: ‘Error: Can’t open display: :0’, ‘cannot open display: localhost:10.0’, or ‘Gtk-WARNING **: cannot open display’ halts graphical application execution. In Unix and Linux graphical desktop architecture, GUI applications do not draw directly to the physical screen; instead, they act as clients communicating with an X11 Display Server or Wayland Compositor via network sockets. When the DISPLAY environment variable is unset, access control permissions reject the client, or X11 forwarding is unconfigured, the display server rejects the application.
Why Does Linux Return ‘Cannot Open Display’?
The display error indicates that the graphical application cannot locate or authenticate with an active X11/Wayland display server socket:
- Unset or Misconfigured DISPLAY Variable: The shell environment lacking the
DISPLAYvariable (e.g.:0or:1) needed to locate local Unix domain sockets in/tmp/.X11-unix/. - X11 Access Control Restrictions (xhost): The active desktop user session rejecting connection requests initiated by root (via
sudo) or another local user account. - Disabled SSH X11 Forwarding: Connecting remotely via SSH without enabling trusted X11 forwarding flags (
-Xor-Y) or server-side X11 forwarding insshd_config. - Missing X11 Socket Mounts in Docker Containers: Launching a GUI app inside a container without passing
/tmp/.X11-unixand$DISPLAY. - Wayland Session Authorization Mismatches: Wayland enforcing strict application isolation, preventing traditional X11 apps from accessing the compositor.
Step 1: Check and Set the DISPLAY Environment Variable
Verify whether your current shell knows which display server socket to communicate with.
- In your terminal, print the active DISPLAY variable:
echo $DISPLAY - If the output is completely blank, export the standard local display identifier:
export DISPLAY=:0 # Or export DISPLAY=:1 - To find the exact active display session on your desktop:
who | grep '(' - Launch your GUI application again.
Step 2: Grant X11 Display Server Access with xhost
If running graphical applications under sudo or a secondary user, authorize local client connections.
- As the primary logged-in desktop user (do not run this command as root), execute:
xhost +local: - This grants all local users on the machine permission to connect to your active X display server.
- Now run your administrative command:
(Thesudo -E gedit /etc/fstab-Eflag preserves your user’s existing environment variables, including$DISPLAYand$XAUTHORITY).
Step 3: Enable X11 Forwarding Over SSH
If connecting to a remote Linux server and attempting to view GUI tools locally, configure SSH X11 forwarding.
- On the remote server, ensure X11 forwarding is permitted in
/etc/ssh/sshd_config:X11Forwarding yes X11DisplayOffset 10 X11UseLocalhost yes - Restart the SSH service if changes were made:
sudo systemctl restart sshd - When connecting from your local client machine, add the trusted forwarding flag:
ssh -Y user@remote-server-ip - Once connected,
echo $DISPLAYwill automatically displaylocalhost:10.0. Launch your GUI tool.
Step 4: Pass Display Sockets to Docker Containers
When running graphical applications inside Docker containers, bind mount the X11 socket directory.
- Authorize local connections on the host:
xhost +local:docker - Launch your Docker container with the display environment and socket mounted:
docker run -it --rm \ -e DISPLAY=$DISPLAY \ -v /tmp/.X11-unix:/tmp/.X11-unix \ image_name
Step 5: Fall Back to Xorg Session on Wayland Desktops
If Wayland security isolation prevents legacy tools from drawing, switch to an Xorg session.
- Log out of your current Ubuntu desktop session.
- On the login screen, click your username, then click the gear icon in the bottom right corner.
- Select Ubuntu on Xorg instead of the default Wayland.
- Enter your password to log in. Traditional X11 graphical tools will now launch seamlessly.
Setting the DISPLAY variable, granting local permissions via xhost +local:, and enabling SSH X11 forwarding resolves ‘Cannot open display’ errors in Ubuntu and Linux.