Skip to content

Instantly share code, notes, and snippets.

@dPacc
Created April 14, 2025 11:03
Show Gist options
  • Save dPacc/46d37666953ad536f514f95d8e84aa07 to your computer and use it in GitHub Desktop.
Save dPacc/46d37666953ad536f514f95d8e84aa07 to your computer and use it in GitHub Desktop.

Setting Up Chromium and ChromeDriver for Browser Automation on Ubuntu

This guide explains how to properly set up Chromium and ChromeDriver on Ubuntu servers for browser automation tasks using tools like Selenium WebDriver.

The Problem with Ubuntu's Default Chromium Package

On Ubuntu (especially 20.04 and newer), the chromium-browser package in the default repositories is actually just a transitional package that redirects to the Snap version. This Snap-packaged version of Chromium runs in a confined environment with restricted filesystem access, which often causes permission issues when used with browser automation tools.

Common errors you might encounter with the Snap version include:

  • cannot create default profile directory
  • probably user data directory is already in use
  • Permission errors when trying to access certain directories

Step-by-Step Installation Guide

1. Remove Existing Chromium Installations

First, remove any existing Chromium installations to avoid conflicts:

# Remove the apt transitional package
sudo apt remove chromium-browser

# Remove the snap version if installed
sudo snap remove chromium

2. Install a Proper Debian-packaged Chromium

There are several ways to install a Debian-packaged version of Chromium:

Option A: Using a PPA (Recommended)

# Add the PPA repository
sudo add-apt-repository ppa:saiarcot895/chromium-dev
sudo apt update

# Install Chromium browser
sudo apt install chromium-browser

Option B: Using Ungoogled Chromium

If you prefer Ungoogled Chromium (a version with Google services removed):

# Add the repository
echo 'deb http://download.opensuse.org/repositories/home:/ungoogled_chromium/Ubuntu_Focal/ /' | sudo tee /etc/apt/sources.list.d/ungoogled-chromium.list

# Add the repository key
wget -O - https://download.opensuse.org/repositories/home:ungoogled_chromium/Ubuntu_Focal/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/ungoogled-chromium.gpg > /dev/null

# Update and install
sudo apt update
sudo apt install ungoogled-chromium

3. Verify Chromium Installation

After installation, verify that Chromium is properly installed:

# Check the binary location
which chromium-browser

# Check the version
chromium-browser --version

The output should show a valid path (typically /usr/bin/chromium-browser) and version number, without any messages referring to Snap.

4. Install ChromeDriver

ChromeDriver is essential for Selenium to interact with Chromium. The ChromeDriver version must match your Chromium version (at least the major version number).

# Get your Chromium version number
CHROME_VERSION=$(chromium-browser --version | cut -d' ' -f2 | cut -d'.' -f1)

# Download the matching ChromeDriver
wget -N https://chromedriver.storage.googleapis.com/$(curl -s https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$CHROME_VERSION)/chromedriver_linux64.zip

# Unzip and install
unzip -o chromedriver_linux64.zip
sudo mv chromedriver /usr/local/bin/
sudo chmod +x /usr/local/bin/chromedriver

# Verify installation
chromedriver --version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment