Skip to main content

Unable to Open X Display When Running Google Chrome on Ubuntu

When you try to run Google Chrome on a headless Ubuntu machine, you may see:
[4520:4520:0529/072952.636189:ERROR:ui/ozone/platform/x11/ozone_platform_x11.cc:248] Missing X server or $DISPLAY
[4520:4520:0529/072952.636223:ERROR:ui/aura/env.cc:257] The platform failed to initialize. Exiting.
This indicates the X server is not running or the $DISPLAY environment variable is not set. The solution is to use Xvfb (X Virtual Framebuffer), which provides a virtual display without requiring physical hardware.
1
Install Xvfb
2
sudo apt-get install -y xvfb
3
Install Dependencies for Headless Chrome / Selenium
4
sudo apt-get -y install xorg xvfb gtk2-engines-pixbuf
sudo apt-get -y install dbus-x11 xfonts-base xfonts-100dpi xfonts-75dpi xfonts-cyrillic xfonts-scalable
5
(Optional) Install Screenshot Capture Utilities
6
If you need to capture screenshots of the Xvfb display:
7
sudo apt-get -y install imagemagick x11-apps
8
Start Xvfb and Export the DISPLAY Variable
9
Add the following to your .bashrc or .profile so the virtual display starts automatically on login:
10
Xvfb -ac :99 -screen 0 1280x1024x16 &
export DISPLAY=:99
11
The :99 is an arbitrary display number. You can choose any unused display number. The 1280x1024x16 sets the screen resolution and colour depth.
12
Launch Google Chrome
13
google-chrome

Build docs developers (and LLMs) love