User Agents

Web browsers and everyday web tech, explained

How to Install Headless Chrome on Linux

· 5 min read · Browsers

In this article
  1. Understanding Headless Chrome
  2. Step-by-Step Installation Guide
  3. How to Run Chrome in Headless Mode
  4. Common Integration Methods
  5. Troubleshooting Common Linux Issues
  6. Comparison: Headless Chrome vs. Chromium
  7. Frequently Asked Questions

To install headless Chrome on Linux, you must download the Google Chrome stable package and install it using your distribution's package manager (such as apt or yum), then execute the browser with the --headless flag. Because headless Chrome is simply the standard Chrome browser running without a graphical user interface (GUI), no separate "headless-only" binary is required.

Understanding Headless Chrome

Headless Chrome is a mode of operation for the Google Chrome browser that allows it to function without a visible window. Instead of rendering pixels to a screen for a human user, the browser processes the HTML, CSS, and JavaScript of a webpage in the background. This makes it an essential tool for developers and system administrators who need to automate tasks that require a full browser engine.

Unlike simple HTTP libraries (such as curl or requests in Python), which only download the raw HTML source code, headless Chrome executes JavaScript. This is critical for modern web applications built with frameworks like React, Vue, or Angular, where the content is generated dynamically after the initial page load. Without a browser engine, these pages would appear empty or incomplete to an automated script.

Step-by-Step Installation Guide

The installation process varies slightly depending on your Linux distribution, but the general workflow involves updating your system, downloading the .deb or .rpm package, and installing the necessary dependencies.

Installation on Debian/Ubuntu

  1. Update your local package index to ensure you have the latest metadata: sudo apt update
  2. Install wget if it is not already present: sudo apt install wget
  3. Download the latest stable Google Chrome package: wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
  4. Install the package: sudo apt install ./google-chrome-stable_current_amd64.deb
  5. If the installation reports missing dependencies, fix them with: sudo apt --fix-broken install

Installation on CentOS/RHEL/Fedora

  1. Download the RPM package: wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
  2. Install using the dnf or yum manager: sudo dnf install ./google-chrome-stable_current_x86_64.rpm

How to Run Chrome in Headless Mode

Once installed, you can trigger headless mode by adding specific flags to the command line. The most common way to verify the installation is to request a page and output the result to the terminal.

Run the following command to take a screenshot of a webpage without opening a window:

  • google-chrome --headless --disable-gpu --screenshot https://www.google.com

The --disable-gpu flag was historically required on many Linux servers because they lack a physical graphics card, though newer versions of Chrome have improved how they handle hardware acceleration in headless mode. The --headless=new flag is often recommended for versions 109 and later, as it utilizes the "new" headless mode which more closely mimics the behavior of the headed browser.

Common Integration Methods

While running Chrome from the command line is useful for testing, most users integrate headless Chrome into automation frameworks. This allows for complex interactions like clicking buttons, filling out forms, and navigating through multi-step workflows.

  • Puppeteer: A Node.js library developed by Google that provides a high-level API to control Chrome over the DevTools Protocol. It is the most popular choice for Chrome automation.
  • Selenium: A cross-browser automation tool. To use it with headless Chrome, you must download the chromedriver binary that matches your Chrome version and configure the ChromeOptions class to include the --headless argument.
  • Playwright: A modern alternative to Selenium and Puppeteer that supports multiple browser engines (Chromium, Firefox, WebKit) and offers faster execution and better reliability.

Troubleshooting Common Linux Issues

Running Chrome on a headless server often leads to specific errors related to permissions and missing libraries.

The Sandbox Error: By default, Chrome uses a sandbox to isolate browser processes for security. On some Linux environments (especially inside Docker containers), the sandbox cannot initialize, resulting in a crash. You can bypass this using the --no-sandbox flag, but this should only be done in trusted environments as it reduces security.

Missing Shared Libraries: If you try to run Chrome and receive errors about missing .so files (such as libatk-1.0.so.0 or libnss3.so), it means your server is missing the GUI libraries Chrome depends on. You can resolve this by installing the necessary X11 and graphics libraries via your package manager, even if you never intend to actually use a monitor.

Comparison: Headless Chrome vs. Chromium

When searching for installation methods, you will often see references to Chromium. Chromium is the open-source project upon which Google Chrome is built. For most headless tasks, they are interchangeable, but there are key differences:

  • Installation: Chromium is often available directly in the official Linux repositories (e.g., sudo apt install chromium-browser), making it faster to install than downloading a .deb file from Google.
  • Proprietary Codecs: Google Chrome includes proprietary codecs (like H.264) for video playback that Chromium may lack. If your automation requires interacting with copyrighted video content, Google Chrome is the better choice.
  • Updates: Google Chrome updates automatically via the Google repository, whereas Chromium updates follow the distribution's package cycle.

Frequently Asked Questions

Do I need a desktop environment to run headless Chrome?

No, you do not need a desktop environment like GNOME or KDE. Headless Chrome is designed specifically to run on servers and CLI-only environments. However, you still need to install the underlying system libraries that Chrome expects to find on a Linux system.

How can I check which version of Chrome is installed?

You can check the version by running google-chrome --version in your terminal. This is important because if you are using Selenium, your chromedriver version must match your browser version exactly to avoid compatibility errors.

Can I run headless Chrome as the root user?

Chrome prevents running as root for security reasons. If you must run it as root (for example, inside a Docker container), you must add the --no-sandbox flag to the command, otherwise the browser will refuse to start.

Will headless Chrome be detected by websites?

Yes, many websites can detect headless browsers by checking for specific browser fingerprints, such as the navigator.webdriver property. To avoid detection, developers often use plugins like puppeteer-extra-plugin-stealth to mask the headless nature of the browser.

Is headless Chrome slower than a standard browser?

In terms of raw page processing, it is often faster because it does not have to spend resources rendering the visual UI. However, the overall speed depends on the hardware and the complexity of the JavaScript being executed on the target page.