cannot open display

Linux Linux

Severity: Minor

What it means

A program with a window can't reach your desktop, so it stops.
GTK programs write Gtk-WARNING: cannot open display, followed by a name such as :0.
Others write Error: Can't open display.
The steps come from answers on Ask Ubuntu and on Unix & Linux Stack Exchange that worked for the people who asked or for others with the same message.

Affected Models

  • Ubuntu and other Linux systems with X11 or Wayland

How to Fix It

  1. Did you start it with sudo, or as root?
    On Ubuntu with Wayland, programs of root aren't allowed on your desktop.
    In a terminal of your own user, type: xhost +SI:localuser:root

    Then start the program again.
    GParted is the best-known example.
    Undo it afterwards with: xhost -SI:localuser:root

  2. Don't use a bare xhost +. It lets everyone show windows on your screen and read what is on it.

  3. Did you connect with SSH?
    Connect with ssh -Y (only to a computer you trust), and look at the variable with: echo $DISPLAY

    If it's empty, the forwarding of windows isn't active.

  4. SSH and still empty?
    Install the package xauth on the remote computer.

    For some people the fix was to set X11UseLocalhost to no in the server's sshd_config, and to restart the SSH service.

  5. Another user on the same desktop?
    That user needs your X key.
    The xauth command passes it on.

Frequently Asked Questions

It's a server without a desktop. Can I still run the program?

Not on the server's own screen.
Use a command-line tool instead, or SSH with -Y from a computer that has a desktop.