How to run X programs on a headless server

Sometimes, it is necessary to start a program that uses X on a headless server, e.g. a remote virtual machine. If you do not really need UI interaction, e.g. using a mouse, then Xvfb is the right tool. Xfvb provides a X server implementation that renders the X commands not using a physical display driver, but only into a virtual frame buffer in main memory.

Before it can be used, it has to be installed, first. On Debian based systems, you enter:

sudo apt-get install xvfb

After installation, Xvfb is started by

Xvfb -ac :99 -screen 0 1280x1024x16

with a single screen of 1280 x 1024 pixels and a color depth of 16 bit on display 99. So in order to use it, you have to set the display environment variable accordingly:

export DISPLAY=:99