I've heard that there is a way launching programs with graphical interface without display manager - straight from terminal. Is this for real and if so, how can I do that?
4 Answers
You can run them with no display manager, but you do need a running X session. The details will depend on your distribution but you should be able to get a minimal X session with a single terminal by running
xinit
I haven't done this in years but, last time I did, that would give something like this:
Once there, you can run a GUI program normally, preferably by launching it in the background (with &
) so you don't loose access to your only terminal.
-
2It might be worth mentioning that "running them normally" will most likely involve backgrounding the process, so you'd most likely want to use
xterm &
to get an additional terminal, not justxterm
. Etc.– userApr 21, 2015 at 18:29
Here is the basics for running an GUI app headless, with a way (vnc
) to connect to it.
Works on RHEL7
and Centos 7
, with family. And ripped out of my own Docker-image that I use for Crashplan located at https://github.com/xeor/dockerfiles/tree/master/crashplan/ (see Dockerfile
for setup, and init/setup
for startup.
# Needed environment variables
export DISPLAY=:99.0
export SCREEN_WIDTH=1200
export SCREEN_HEIGHT=960
export SCREEN_DEPTH=24
export GEOMETRY="${SCREEN_WIDTH}x${SCREEN_HEIGHT}x${SCREEN_DEPTH}"
# Needed packages
yum install -y xorg-x11-server-Xvfb x11vnc gtk2 xorg-x11-fonts-*
# Set a password (if variable vncpass is sat, else its `secret`)
mkdir -p ~/.vnc && x11vnc -storepasswd ${vncpass:-secret} ~/.vnc/passwd
# Start up the fake display and run the application you want (the `java ...` part)
xvfb-run --server-args="$DISPLAY -screen 0 $GEOMETRY -ac +extension RANDR" java .... > log/ui_output.log 2> log/ui_error.log &
# Wait for the app to start, or else, the vnc server will die before starting
sleep 5
# vnc itself
x11vnc -forever -usepw -shared -rfbport 5900 -display $DISPLAY
You should now be able to connect to the server:5900 and see the application.
Yes. Just do the same things a display manager does. Aside from the graphical login screen (which you don't need in this case), the display manager just does two things:
- First it starts an X11 "display server", such as Xorg,
- then starts "clients" which tell Xorg what & where to draw.
You can use tools like startx
to start X11 the same way from a console login; it will launch Xorg followed by the clients listed in your ~/.xinitrc
file.
For example, the .xinitrc file could have startkde
or gnome-session
, or it could list the individual components (the window manager, a panel/taskbar, a desktop...)
(Note that there are some differences between xinit
and startx
– usually you should use the latter, since some distros have a few important pieces of configuration that plain xinit will ignore, namely the xserverrc
script.)
With Wayland, the desktop & panels are an integrated part of the "compositor", so the entire interface starts in a single step without additional tools. For example, you can run weston
or start GNOME using gnome-session --session=gnome-wayland
.
You can launch X applications using ssh X forwarding (ssh -X; may need to be enabled in server config as well), provided you have a local X display.
The application will launch and display locally, while running on a headless system. You will need to have X installed on the headless system in order to have the right libraries, and this may not work with more modern GNOME applications.
You can also use $DISPLAY
to launch apps on an attached X display even if your shell is a remote one (ssh or console). If you're root and the person logged in on the X display isn't, you can override the xauth
security and pop up a window on their display anyway. This also works if you have two different X display servers on different monitors.
Another poster mentions VNC; I've also used NX for this purpose, and I prefer it.
xinit
orstartx
?