How to install Xvfb on Ubuntu

Xvfb, or X virtual framebuffer, is a virtual display server that allows you to run graphical applications on a headless server, where there is no physical display connected. This is useful for running programs that require a graphical user interface (GUI), such as web browsers, office suites, and other desktop applications. To install Xvfb on Ubuntu, there are a few steps you need to follow.

First, you should update your system’s package index and upgrade any existing packages to their latest versions. This ensures that you have the latest version of the package manager and all the necessary libraries and dependencies. To do this, run the following commands in your terminal:

sudo apt-get update
sudo apt-get upgrade

Once your system is up to date, you can use the apt package manager to install Xvfb and any required dependencies. The installation process is straightforward, to install Xvfb on Ubuntu you can do it using a single command:

sudo apt-get install xvfb

After the installation is complete, you can verify that Xvfb is installed and working by running the command “Xvfb -help” in the terminal. This will display the help documentation for Xvfb, which confirms that the installation was successful. You can verify that Xvfb is installed by running the following command:

Xvfb -help

To automatically start Xvfb when your machine starts up, you can create a system service that starts Xvfb on boot. Here’s one way to create a systemd service on Ubuntu:

Create a new service file using a text editor such as nano:

sudo nano /etc/systemd/system/xvfb.service

Paste the following contents into the file:

Description=Xvfb virtual display server

ExecStart=/usr/bin/Xvfb :99 -screen 0 1024x768x16


Save and exit the file.

Reload the systemd daemon to pick up the new service:

sudo systemctl daemon-reload

Start the Xvfb service:

sudo systemctl start xvfb

You can also enable the service to start automatically on boot:

sudo systemctl enable xvfb

Once you have created and enabled the xvfb.service file, Xvfb will automatically start when your machine boots up. You can check the status of the service by running systemctl status xvfb.

systemctl status xvfb


● xvfb.service - Xvfb virtual display server
     Loaded: loaded (/etc/systemd/system/xvfb.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2023-02-16 20:18:06 UTC; 14s ago
   Main PID: 220331 (Xvfb)
      Tasks: 1 (limit: 9520)
     Memory: 15.5M
        CPU: 54ms
     CGroup: /system.slice/xvfb.service
             └─220331 /usr/bin/Xvfb :99 -screen 0 1024x768x16

Feb 16 20:18:06 ip-172-31-20-112 systemd[1]: Started Xvfb virtual display server.