This guide explains how to properly set up Chromium and ChromeDriver on Ubuntu servers for browser automation tasks using tools like Selenium WebDriver.
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
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
There are several ways to install a Debian-packaged version of Chromium:
# Add the PPA repository
sudo add-apt-repository ppa:saiarcot895/chromium-dev
sudo apt update
# Install Chromium browser
sudo apt install chromium-browser
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
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.
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