I'm trying to run an appliaction, but when I run it I get a

Could not open display `(null').

Error. Why is this? Specifically I was trying to run scratch (which I installed via aws):

root@ip-10-251-56-90:/usr/bin# ./scratch
Executing: /usr/lib/squeak/4.4.7-2357/squeakvm -encoding UTF-8 -vm-display-x11 -xshm -plugins /usr/lib/scratch/plugins/:/usr/lib/squeak/4.4.7-2357/ -vm-sound-ALSA /usr/share/scratch/Scratch.image
Could not open display `(null)'.

Errors like this mean that you are running a program that needs a graphical display and it can't find one. GUI programs connect to the display defined by the $DISPLAY environmental variable. The general format of the error is

Could not open display $DISPLAY

Since, in your case, the error says (null), this means that $DISPLAY is not set. You therefore need to:

  1. If you are logging in to a remote machine using something like ssh, you will need to export the $DISPLAY of your local machine and tell the remote computer to display GUI programs there. This can be done with the -X or -Y options of ssh:

    ssh -Y root@10.251.56.90
    

    As explained in man ssh:

     -Y  Enables trusted X11 forwarding.  Trusted X11 forwardings are not
         subjected to the X11 SECURITY extension controls.
     -X  Enables X11 forwarding.  This can also be specified on a per-host
         basis in a configuration file.
    
  2. If this is your local machine, you need to install a graphical environment. If one is already installed, assuming a default Ubuntu setup, you can start it with this command:

    sudo service lightdm start
    
  3. If you have a graphical environment running but for whatever reason, $DISPLAY is set to null, you can redefine it. The details will depend on your actual situation but in most cases, what you will need (assuming, again, you are on your local machine) is

    export DISPLAY=:0.0
    

    You can then run your GUI program normally.

  4. If you do have an X server running but have switched to a tty (for example by pressing Ctrl+Alt+F1), you might simply need to return to your graphical environment. This depends on which virtual console your GUI is running but in most cases on Ubuntu that will be 7, so you can get back to it using Alt+F7.

    If that does not bring you back to your desktop, just cycle through all ttys Alt+Left Arrow or Alt+Right Arrow until you find the right one.

  5. Another common problem is that you have started an X session as your normal user and are now trying to connect to it as root or another user. To enable this, you need to specify that this user has the right to access your graphical desktop. For example:

    xhost +si:localuser:terdon
    

    That will allow the local user terdon to connect to the running X server. The command needs to be run by the owner of the X session. Alternatively, to allow anyone to connect:

    xhost +
    

    And to revoke permissions:

    xhost -
    

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.