What is DISPLAY=:0?

What is DISPLAY=:0 and what does it mean?

It isn’t a command, is it? (gnome-panel is a command.)

DISPLAY=:0 gnome-panel


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

It’s an environment variable that is passed just to that program, rather than the shell as a whole. This happens when you set a variable on the same line as a command.

X11 programs need to know where to display windows, since it’s a client/server system and you could be displaying on a remote machine. This simply means use the first display on the local machine.

This is normally set up automatically when logging in to a desktop environment. For example, open a graphical terminal and type echo $DISPLAY.

Method 2

DISPLAY=:0 gnome-panel is a shell command that runs the external command gnome-panel with the environment variable DISPLAY set to :0. The shell syntax VARIABLE=VALUE COMMAND sets the environment variable VARIABLE for the duration of the specified command only. It is roughly equivalent to (export VARIABLE=VALUE; exec COMMAND).

The environment variable DISPLAY tells GUI programs how to communicate with the GUI. A Unix system can run multiple X servers, i.e. multiple display. These displays can be physical displays (one or more monitor), or remote displays (forwarded over the network, e.g. over SSH), or virtual displays such as Xvfb, etc. The basic syntax to specify displays is HOST:NUMBER; if you omit the HOST part, the display is a local one.

Displays are numbered from 0, so :0 is the first local display that was started. On typical setups, this is what is displayed on the computer’s monitor(s).

Like all environment variables, DISPLAY is inherited from parent process to child process. For example, when you log into a GUI session, the login manager or session starter sets DISPLAY appropriately, and the variable is inherited by all the programs in the session. When you open an SSH connection with X forwarding, SSH sets the DISPLAY environment variable to the forwarded connection, so that the programs that you run on the remote machine are displayed on the local machine. If there is no forwarded X connection (either because SSH is configured not to do it, or because there is no local X server), SSH doesn’t set DISPLAY.

Setting DISPLAY explicitly causes the program to be displayed in a place where it normally wouldn’t be. For example, running DISPLAY=:0 gnome-panel in an SSH connection starts a Gnome panel on the remote machine’s local display (assuming that there is one and that the user is authorized to access it). Explicitly setting DISPLAY=:0 is usually a way to access a machine’s local display from outside the local session, such as over a remote access or from a cron job.

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments