This is likely due to either a misconfiguration issue or you have multiple displays. As can be seen in the xterm manpage (man xterm) you can set the display using the -display flag:
-display display
This option specifies the X server to contact; see X(7).
If you then look in X(7) where it specifies to look (man X) you will see what you need to put after the flag:
DISPLAY NAMES
From the user's perspective, every X server has a display name of the
form:
hostname:displaynumber.screennumber
This information is used by the application to determine how it should
connect to the server and which screen it should use by default (on
displays with multiple monitors):
hostname
The hostname specifies the name of the machine to which the
display is physically connected. If the hostname is not given,
the most efficient way of communicating to a server on the same
machine will be used.
displaynumber
The phrase "display" is usually used to refer to a collection
of monitors that share a common set of input devices (keyboard,
mouse, tablet, etc.). Most workstations tend to only have one
display. Larger, multi-user systems, however, frequently have
several displays so that more than one person can be doing
graphics work at once. To avoid confusion, each display on a
machine is assigned a display number (beginning at 0) when the
X server for that display is started. The display number must
always be given in a display name.
screennumber
Some displays share their input devices among two or more moni‐
tors. These may be configured as a single logical screen,
which allows windows to move across screens, or as individual
screens, each with their own set of windows. If configured
such that each monitor has its own set of windows, each screen
is assigned a screen number (beginning at 0) when the X server
for that display is started. If the screen number is not
given, screen 0 will be used.
On POSIX systems, the default display name is stored in your DISPLAY
environment variable. This variable is set automatically by the xterm
terminal emulator. However, when you log into another machine on a
network, you may need to set DISPLAY by hand to point to your display.
For example,
% setenv DISPLAY myws:0
$ DISPLAY=myws:0; export DISPLAY
The ssh program can be used to start an X program on a remote machine;
it automatically sets the DISPLAY variable correctly.
Finally, most X programs accept a command line option of -display dis‐
playname to temporarily override the contents of DISPLAY. This is most
commonly used to pop windows on another person's screen or as part of a
"remote shell" command to start an xterm pointing back to your display.
For example,
% xeyes -display joesws:0 -geometry 1000x1000+0+0
% rsh big xterm -display myws:0 -ls </dev/null &
X servers listen for connections on a variety of different communica‐
tions channels (network byte streams, shared memory, etc.). Since
there can be more than one way of contacting a given server, The host‐
name part of the display name is used to determine the type of channel
(also called a transport layer) to be used. X servers generally sup‐
port the following types of connections:
local
The hostname part of the display name should be the empty
string. For example: :0, :1, and :0.1. The most efficient
local transport will be chosen.
TCPIP
The hostname part of the display name should be the server
machine's hostname or IP address. Full Internet names, abbre‐
viated names, IPv4 addresses, and IPv6 addresses are all
allowed. For example: x.org:0, expo:0, [::1]:0,
198.112.45.11:0, bigmachine:1, and hydra:0.1.
To get the value of your display you should just be able to run:
echo $DISPLAY
Overview
I’m attempting to get XQuartz to work on OSX so I can do X11 forwarding via Docker. I’m following the instructions here. I believe my question may be answered by just the first part, but just in case (to avoid the XY problem), I’ve provided the second part as well.
Installation
I’ve installed it via homebrew, via brew cask install xquartz. Then I open -a XQuartz to start it.
Local xterms
Testing it out, if I try to open an xterm, it does not work:
MacBook-Pro:opencv-gui csaftoiu$ xterm
xterm: Xt error: Can't open display: /private/tmp/com.apple.launchd.3wncZULdXC/org.macosforge.xquartz:0
The pseudo-file exists, though:
MacBook-Pro:opencv-gui csaftoiu$ echo $DISPLAY
/private/tmp/com.apple.launchd.3wncZULdXC/org.macosforge.xquartz:0
MacBook-Pro:opencv-gui csaftoiu$ ls -alh $DISPLAY
srw-rw-rw- 1 csaftoiu wheel 0B May 6 21:12 /private/tmp/com.apple.launchd.3wncZULdXC/org.macosforge.xquartz:0
I can open an xterm via XQuartz. Then:
bash-3.2$ echo $DISPLAY
:0
This value works from a regular OSX too:
$ DISPLAY=:0 xterm
# opens xterm, waits for it to finish
$
The following do not work though, not sure why based on the answer here:
xterm: Xt error: Can't open display: localhost:0
MacBook-Pro:opencv-gui csaftoiu$ DISPLAY=127.0.0.1:0 xterm
xterm: Xt error: Can't open display: 127.0.0.1:0
MacBook-Pro:opencv-gui csaftoiu$ DISPLAY=`ipconfig getifaddr en0`:0 xterm
xterm: Xt error: Can't open display: 192.168.1.15:0
Note that xinit does work for some reason:
$ xinit
xinit: XFree86_VT property unexpectedly has 0 items instead of 1
# opens xterm, waits for it to finish
xinit: connection to X server lost
waiting for X server to shut down
Question 1: What is XQuartz actually listening on?
Docker Forwarding with socat
In any case, moving on, this socat command does not work:
MacBook-Pro:opencv-gui csaftoiu$ socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:"$DISPLAY"
Running that, from another window I do:
MacBook-Pro:opencv-gui csaftoiu$ docker run --rm -it -e DISPLAY=`ipconfig getifaddr en0`:0 ubuntu:14.04 bash
root@912eec31b8cb:/# apt-get update && apt-get install xterm
... such install, wow ...
root@912eec31b8cb:/# xterm
Warning: This program is an suid-root program or is being run by the root user.
The full text of the error or warning message cannot be safely formatted
in this environment. You may get a more descriptive message by running the
program as a non-root user or by removing the suid bit on the executable.
xterm: Xt error: Can't open display: %s
root@912eec31b8cb:/# echo $DISPLAY
192.168.1.15:0
From the socat window I get:
2016/06/14 21:08:15 socat[24289] E connect(5, LEN=68 AF=1 "/private/tmp/com.apple.launchd.3wncZULdXC/org.macosforge.xquartz:0", 68): Connection refused
I can’t use the DISPLAY variable that works, either:
MacBook-Pro:opencv-gui csaftoiu$ socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:":0"
2016/06/14 21:09:43 socat[24309] E connect(5, LEN=4 AF=1 ":0", 4): No such file or directory
Now, this is not a UNIX-CLIENT IP. But, I don’t know what DISPLAY=:0 is connecting to. It’s certainly not port 6000 since that’s the port it used to be listening on. If I change it to 6005, to forward to 6000, and make the Docker container DISPLAY be $(ipconfig getifaddr en0):5 instead, then the connection is of course refused:
$ socat TCP-LISTEN:6005,reuseaddr,fork TCP:localhost:6000
2016/06/14 21:20:32 socat[25379] E connect(8, LEN=16 AF=2 127.0.0.1:6000, 16): Connection refused
Question 2: How to proceed from here?
In the attached picture is a cygwin terminal window. This is kind of similar to Windows Command Prompt: it cannot display any graphics. To use xterms, you must run the X11 server component of Cygwin, also known as Cygwin-X.
Apparently you’re using the traditional X11 connection procedure, which results in an unencrypted X11 connection: anyone on the same network can spy on your keyboard and mouse actions. But if you need to use it anyway, here’s some diagnostics.
When you start Cygwin-X on Vista for the first time, it is likely that the Windows Firewall or the firewall component of your Windows security solution reports that Cygwin-X is trying to act as a network server on TCP port 6000. To make unencrypted X11 connections work, you must allow this.
When your Cygwin-X (or other X server) is running on your PC, you should be able to reach it from the HP-UX box using telnet to port <DISPLAY number + 6000>. For example:
telnet 192.165.15.3 6000
This connection will not produce any meaningful command prompt; but if the telnet command says «Connection established» (or the equivalent text for your locale/language), then the unencrypted X11 connection is possible.
However, instead of Cygwin-X I would suggest Xming, for it’s easier to start up and works well with PuTTY’s X11 forwarding function (assuming you use the SSH connection method, not telnet or rlogin).
You can find the latest free Xming and Xming-fonts packages from Sourceforge:
http://sourceforge.net/projects/xming/files/
They are normal Windows self-extracting install packages; just install them using the default values. First Xming, then Xming-fonts.
Then start Xming; it will add its icon in the notification area in the bottom right corner of your screen. You won’t have to do anything else with it.
Then start PuTTY. If you have a pre-configured session, select it and click Load. If you don’t have one, just type the hostname or IP of the HP-UX box to the destination field in the PuTTY configuration dialog. But don’t press Enter or click Login/Open just yet!
Before logging in, go to Connection -> SSH -> X11 in the PuTTY configuration dialog and check the checkbox «Enable X11 forwarding». You can leave the «X display location» field empty. (If you want, you can save the connection settings at this time, with a descriptive name, like «<your HP-UX> with X11») Then start the connection.
When you login with X11 forwarding for the first time, you may see a message telling that sshd has created the $HOME/.Xauthority file on the HP-UX box. If the file already exists, you won’t see this message (and it’s information only anyway).
If the sshd daemon on HP-UX was configured to allow X11 forwarding, your DISPLAY should already be set to a strange-looking value, for example something like 127.0.0.1:10.0. Don’t change it: the value is set automatically by sshd and is required for the SSH X11 forwarding to work. Because sshd also has created the X authority keys for you, you don’t need any «xhost +» commands either.
Now, if you run something like «xterm &» on your PuTTY window, you should get a xterm window on your Windows display. You can run any X11 applications in the same way. If you log out in the PuTTY window, PuTTY is smart enough to wait for the X11 applications to stop before actually closing the connection; but if you force-close PuTTY, all your running remote X11 application windows will be forced to close too.
If you saved the PuTTY connection settings, connecting again will be very simple:
- make sure Xming is running
- start PuTTY
- select the connection settings you saved and click Login (or Open, in some versions of PuTTY)
MK
“Xterm display is not set” is an error message that advanced Linux users must have encountered at some point. Xterm is a Terminal Emulator that works on top of the operating system’s default terminal emulator. It is used to run command-line programs while still working in the GUI background. Xterm is the default standard terminal system for the X Window System desktop environment. Xterm runs the user shell, i.e., the default shell on the user’s system. The official website for Xterm is https://invisible-island.net/xterm/.
Contents
- 1 What is Xterm
- 2 Installing Xterm
- 2.1 Installing Xterm on Debian Based OS
- 2.2 Downloading the source code
- 3 Xterm Display is not set
- 4 2 Methods to Fix Xterm Display is Not Set
- 4.1 Dispay variable
- 4.2 Desktop environments
- 5 cygwin xterm display is not set
- 6 Aix xterm: display is not set
- 7 WSL xterm not opening display is not set
- 8 FAQs
- 8.1 Is Xterm available in Windows?
- 8.2 What do you mean by FTP?
- 8.3 What is the full form of SSh and SSL?
- 9 Conclusion
- 10 Trending Now
What is Xterm
Xterm is a terminal emulator aside from the default terminal emulators of the operating system. Xterm runs over the user’s terminal and uses the same shell as the user’s default. Unlike other terminal emulators that can just run without a graphical display output, Xterm requires a GUI to run. Error messages like “Xterm display is not set” can come up in unsuitable environments. It runs on all the UNIX-based operating systems. Just as gnome-terminal is the default terminal emulator of the GNOME desktop environment, Xterm is the default terminal emulator for X Window system environment.

Installing Xterm
If you do not have Xterm installed on your system, you could easily install it using the default package manager of your operating system. Or, if you have Xterm installed already and it is showing “Xterm display is not set,” try reinstalling or updating the package as it might help eradicate the error problem. Different distributions of Linux use other package managers to download and install programs. For example, Debian-based distros use dpkg package manager while Arch-based distributions use Pacman.
Installing Xterm on Debian Based OS
Follow the given steps to download and install Xterm on Debian-based systems.
- Open the default terminal emulator.
- Type the following command in the shell.
sudo apt install xterm
- You would be prompted to enter the root password in order to install it.
- Enter Y(yes) when promted to, wait for the downloading and installation to complete.

Downloading the source code
If you are on other platforms than Debian, you could download the source code file from the official website of Xterm and then extract it yourself on your system. follow the steps to download the term source code manually.
- Head to Xterm’s official website. https://invisible-island.net/xterm/
- Under the download section. choose the protocol you want to use to download the compressed file.
- Choose http if you are using a browser or ftp is downloading through terminal.
- Download the tar.gz file and extract it.

As mentioned earlier, Xterm requires a GUI display environment to work seamlessly. If the DISPLAY environment variable is not set for the Xterm terminal emulator, it won’t work, and ‘Xterm display is not set’ would be shown as the output. If you are using an SSL connection to a remote server that doesn’t have any display environment installed, you are more likely to face an Xterm display is not set issue.
- input:
xterm
- output:
xterm: Xt error: Can't open display:
xterm: DISPLAY is not set
2 Methods to Fix Xterm Display is Not Set
The following fixes can be tried to resolve the Xterm display is not set issue.
Dispay variable
The “Xterm display is not set issue” can be resolved by setting the DISPLAY environment in the terminal before connecting to the remote host. Run the following commands shown in the image to set your display output variable and then log in to the ssh session with the remote host.

NOTE – The username and remote host are to be replaced with the actual username and remote-host name of the server you are trying to connect, respectively.
Desktop environments
A desktop environment is a set of GUI programs that runs on top of the underlying operating system. It is responsible for all the visible elements of the operating system. The same underlying operating system can have different desktop environments. Users can even switch to other desktop environments without reinstalling the operating system as per their appearance or performance preferences. Some famous desktop environments are Gnome, KDE, Xfce, etc. The point is, an operating system can run even without a desktop environment, for example, vanilla Arch Linux.
In such a case, only a command-line terminal is available to interact with the system, so the applications that depend on the GUI elements like Xterm would not work. Therefore another way to resolve the “Xterm display is not set” issue is to ensure that the host system has a suitable desktop environment. If the problem persists trying switching the environment. You could visit the official websites of the popular desktop environments of your choice and follow the installation process mentioned there.
cygwin xterm display is not set
Cygwin is a Unix-based programming runtime environment compatible with Microsoft windows. Unix-based applications can efficiently be run on Windows using the Cygwin environment. Xterm is a GUI-based program and requires an X windows system to run, Which can be done by running an X server on the host system. The Xterm would show the error message “Xterm display is not set without the X server running.”
To work around this issue, you need to install two packages in your Cygwin environment, Xorg-server and xinit. After installing these two packages, start the server by running the startxwin command and then set the display variable below.
Aix xterm: display is not set
Aix, which stands for Advanced Interactive Executive, is a proprietary operating system series based on UNIX. Again, to run Xterm in this AIX environment Display variable needs to be set. And the X server needs to be started. Run the following commands to eradicate the “xterm display is not set” error.
startx
xclock
export DISPLAY=localhost:0.0
xinit
WSL xterm not opening display is not set
WSL is short for Windows Subsystem for Linux; it is a compatibility layer between the Microsoft Windows operating system and Linux packages. It allows users to run native Linux binary executables on Windows machines. Using WSL, Xterm can be made to run on Windows. WSL2 has a slightly different way of resolving servers’ name, which could cause issues with X server’s DISPLAY variable. Run the following command to set your display variable in WSL Xterm.
export DISPLAY=$(grep nameserver /etc/resolv.conf | awk '{print $2}'):0.0
FAQs
Is Xterm available in Windows?
No, natively, it is not. It is for UNIX-based OSs.
What do you mean by FTP?
It stands for File Transfer Protocol. It is used to transfer large files across the internet.
What is the full form of SSh and SSL?
The full form of SSh is Secured Shell, and the complete form of SSL is Secure Socket Layer.
Conclusion
Xterm is a terminal emulator like other terminal emulators like gnome-terminal. The difference is, it runs on top of the user’s terminal and even uses the same shell. One additional feature in the Xterm shell is that it supports 8-bit colors. We saw that the “Xterm display is not set” error message can show up if the DISPLAY variable is not set and how to resolve that issues in just two commands. Then we discussed how the desktop environment could make a difference if the problem persists.
Trending Now
-
Resolve Error Code E4301 Using These 4 Exciting Methods
●October 20, 2022
-
15 Incredible Ways to Fix Paramount Plus Keeps Pausing Error
by Amal Santosh●October 20, 2022
-
5 Strategies to Fix Adobe Short Media Token Validation Error Invalid Signature
by Amal Santosh●October 11, 2022
-
Fix the Apple TV 4K Turns off by Itself with 7 Wonderful Ways
by Amal Santosh●October 11, 2022
-
AJSG1969
- Posts: 50
- Joined: Tue Oct 24, 2017 3:24 pm
xterm: Xt error: Can’t open display: %s
This is the bash file:
Code: Select all
Code: Select all
echo "Test Script"
xterm -e "airodump-ng wlan0mon" & sleep 5
pkill airodump-ng
Runs perfectley when called by the command in a Terminal window:
when in crontab I run it like this:
Code: Select all
16 * * * * DISPLAY=:0 xterm -e sudo /home/pi/Desktop/Active/test.sh
I get on screen:
Test Script
No protocol specified
Warning: This program……suid bit on the executable.
xterm: Xt error: Can’t open display: %s
Same error apart from the «No protocol specified». What do you think could be the issue?
Thanks.
Andrew.
-
gkaiseril
- Posts: 679
- Joined: Mon Aug 08, 2016 9:27 pm
- Location: Chicago, IL
Re: xterm: Xt error: Can’t open display: %s
Fri Nov 10, 2017 5:39 pm
It looks like you are calling your script without specifying the shell program to run.
You should include the shebang line as the first line of your script.
#!/bin/bash
or specify the bash shell in the chron entry.
16 * * * * DISPLAY=:0 xterm -e sudo /bin/bash /home/pi/Desktop/Active/test.sh
f u cn rd ths, u cn gt a gd jb n cmptr prgrmmng.
-
AJSG1969
- Posts: 50
- Joined: Tue Oct 24, 2017 3:24 pm
Re: xterm: Xt error: Can’t open display: %s
Fri Nov 10, 2017 8:04 pm
Code: Select all
#!/bin/bash
echo "Test Script"
xterm -e "airodump-ng wlan0mon" & sleep 4
pkill airodump-ng
Unfortunately that wasn’t the problem, still gives me the same issue. Going slightly crazy here as it works perfectly in Ubuntu…
Cheers.
Andrew.
-
Paeryn
- Posts: 3531
- Joined: Wed Nov 23, 2011 1:10 am
- Location: Sheffield, England
Re: xterm: Xt error: Can’t open display: %s
Fri Nov 10, 2017 8:39 pm
It looks like you are ultimately trying to run xterm in the shell script when the script is being run as root. Root won’t ordinarily have authority to open a window on a user’s desktop so the xterm should (and does) fail, the «No protocol specified» and «xterm: Xt error: Can’t open display:» error messages are typical of what you get when a user tries to connect to an X display that the user doesn’t have authority to connect to.
She who travels light — forgot something.
Please note that my name doesn’t start with the @ character so can people please stop writing it as if it does!
-
AJSG1969
- Posts: 50
- Joined: Tue Oct 24, 2017 3:24 pm
Re: xterm: Xt error: Can’t open display: %s
Fri Nov 10, 2017 9:10 pm
Paeryn wrote: ↑
Fri Nov 10, 2017 8:39 pm
It looks like you are ultimately trying to run xterm in the shell script when the script is being run as root. Root won’t ordinarily have authority to open a window on a user’s desktop so the xterm should (and does) fail, the «No protocol specified» and «xterm: Xt error: Can’t open display:» error messages are typical of what you get when a user tries to connect to an X display that the user doesn’t have authority to connect to.
In Ubuntu I set the user as no password like so…
sudo visudo
then add
#includedir /etc/sudoers.d
root ALL=NOPASSWD: ALL
framemanager001 ALL=(ALL:ALL) NOPASSWD: ALL
fm ALL=(ALL:ALL) NOPASSWD: ALL
I have tried running the same in Raspian but get the same issue as previously described.
-
AJSG1969
- Posts: 50
- Joined: Tue Oct 24, 2017 3:24 pm
Re: xterm: Xt error: Can’t open display: %s
Fri Nov 10, 2017 9:14 pm
ait wrote: ↑
Fri Nov 10, 2017 8:10 pm
hello,
just a suggestion:
try it without xterm -e
I can run it from a terminal…
Code: Select all
sudo bash /home/pi/Desktop/Active/a.sh
But from crontab I cannot see it running at all…
Code: Select all
12 * * * * sudo bash /home/pi/Desktop/Active/a.sh
-
Paeryn
- Posts: 3531
- Joined: Wed Nov 23, 2011 1:10 am
- Location: Sheffield, England
Re: xterm: Xt error: Can’t open display: %s
Fri Nov 10, 2017 9:46 pm
AJSG1969 wrote: ↑
Fri Nov 10, 2017 9:10 pm
Paeryn wrote: ↑
Fri Nov 10, 2017 8:39 pm
It looks like you are ultimately trying to run xterm in the shell script when the script is being run as root. Root won’t ordinarily have authority to open a window on a user’s desktop so the xterm should (and does) fail, the «No protocol specified» and «xterm: Xt error: Can’t open display:» error messages are typical of what you get when a user tries to connect to an X display that the user doesn’t have authority to connect to.In Ubuntu I set the user as no password like so…
sudo visudo
then add
#includedir /etc/sudoers.d
root ALL=NOPASSWD: ALL
framemanager001 ALL=(ALL:ALL) NOPASSWD: ALL
fm ALL=(ALL:ALL) NOPASSWD: ALLI have tried running the same in Raspian but get the same issue as previously described.
I don’t know how Ubuntu is doing things but X authorisation doesn’t care whether the user running the program is root or not, the point is that root (or any other user) isn’t ordinarily authorised to connect to a user’s display without having that user’s authorisation key. Root can easily use any user’s authorisation key (since root has access to the user’s file where it is stored) to give itself authority, but just being root should never be enough.
I suppose Ubuntu could be set up so that root@localhost has authority for each user’s X-session, I’ve never set up user-based authorities so not sure on exactly how to specify it.
She who travels light — forgot something.
Please note that my name doesn’t start with the @ character so can people please stop writing it as if it does!
-
AJSG1969
- Posts: 50
- Joined: Tue Oct 24, 2017 3:24 pm
Re: xterm: Xt error: Can’t open display: %s
Sat Nov 11, 2017 8:27 am
Paeryn wrote: ↑
Fri Nov 10, 2017 9:46 pm
I don’t know how Ubuntu is doing things but X authorisation doesn’t care whether the user running the program is root or not, the point is that root (or any other user) isn’t ordinarily authorised to connect to a user’s display without having that user’s authorisation key. Root can easily use any user’s authorisation key (since root has access to the user’s file where it is stored) to give itself authority, but just being root should never be enough.
I’m a little at a loss here, from what I understand the «pi» user has already root authorisation via the sudo command in Raspbian. In Ubuntu the only change I make to run the script is to allow sudo to be run without asking for a password as the script needs to be automated in crontab.
Any help is much appreciated.
Andrew.
Return to “Raspberry Pi OS”




