Cannot open display

Ritratto di jdaemon

When it try to start a graphical application from a terminal and it fails returning only an error of type cannot open display[0] is very likely to be an environment variable error. In Unix-like systems for each Xorg server must be a logical display identifier of the form :0, :1, ..., :0.0, :0.1, ..., :1.0, :1.1 and so forth.

Messages like:

** (PROGRAM_NAME:PORT): CRITICAL **: Failed to parse arguments: Cannot open display:[1]
the most frequent:
(PROGRAM_NAME:PORT): Gtk-WARNING **: cannot open display: VALUE
or even
Error: cannot open display: VALUE

indicate that the VALUE logical display cannot be accessed ...

This is due to the fact that VALUE is the wrong name. In some cases VALUE is empty.

To solve this problem just discover the VALUE in the Xorg process parameters by analyzing the output of this command:

$ ps x | grep -i Xorg[2]

The value of display is the one that begins with colon character (usually :0 equivalent to :0.0). Once identified the display which we assume to be :0.0 proceed with the setting of the DISPLAY environment variable so:

$ export DISPLAY=":0.0"

If it want to make it permanent, I suggest to include this export statement in /home/USER/.bashrc or /etc/profile system files.

[0] The Can't open display and cannot connect to X server errors can be solved in the same manner as the article's subject
[1] It could also be caused by the unavailability of specific programs invoked by other applications
[2] It assumes the process name is Xorg, but it could also be X or something else. If so then suitably grep