DISPLAY environment variable not set

25,932

Solution 1

I solved this problem by simply hardcoding $DISPLAY as :1,

export DISPLAY=:1

in my .bashrc file.

I however, still don't understand why this works. Here is the output of xauth list

ip-172-31-74-230.ec2.internal:1  MIT-MAGIC-COOKIE-1  8a44b41e42cae52c6acd4747763bb985
ip-172-31-74-230.ec2.internal/unix:1  MIT-MAGIC-COOKIE-1  8a44b41e42cae52c6acd4747763bb985
ip-172-31-74-230.ec2.internal:2  MIT-MAGIC-COOKIE-1  e24f36d585762b0c0fe24010b99e448d
ip-172-31-74-230.ec2.internal/unix:2  MIT-MAGIC-COOKIE-1  e24f36d585762b0c0fe24010b99e448d
ip-172-31-74-230.ec2.internal/unix:10  MIT-MAGIC-COOKIE-1  c84bcd904dd50f7776f667eca7a480f5

Solution 2

The DISPLAY environment variable is exported to any x-Client program that needs the specification for the x-server on your original machine (the PC you typed in the ssh command on).

The way I do this these days, is to be lazy and ask the environment:

 $ env | grep SSH
SSH_CLIENT=192.168.182.159 45462 22
SSH_TTY=/dev/pts/28
SSH_CONNECTION=192.168.182.159 45462 192.168.188.120 22

SSH_CLIENT and SSH_CONNECTION show you the IP address of your origin terminal. In which case I export the following:

 $ export DISPLAY="192.168.182.159:0.0"
 $ xeyes

Start-up xeyes to satisfy yourself that everything is working for you. Your display is ready to use.

Share:
25,932
coda
Author by

coda

Software Development Engineer @Amazon

Updated on September 18, 2022

Comments