1. Overview
Gecko is the layout engine used in Mozilla Firefox and Mozilla Thunderbird. It’s actively developed by the Mozilla Foundation. On the other hand, geckodriver is a proxy for using the Gecko engine in software applications. It’s required by software like Selenium.
In this tutorial, we’ll learn how to install geckodriver in Linux. First, we’ll search and install it from the package repositories. Then, we’ll take an alternate approach and download it from its official source repository.
Finally, we’ll turn to a more hardcore approach to compile and install geckodriver from source.
2. Package Repositories
geckodriver comes with the recent versions of Firefox on most distributions. However, some distributions provide geckodriver as a stand-alone package that we can install separately.
In the next sections, we discuss the installation procedure for the major distributions.
2.1. Ubuntu and Ubuntu’s Variants
In recent versions of Ubuntu, geckodriver binary is already pre-installed on the desktop versions. It comes as part of the Mozilla Firefox package, which we can install through snap:
$ sudo snap install firefox
If we prefer the .deb version of Firefox, then we can add its official repository:
$ sudo add-apt-repository -y ppa:mozillateam/ppa
Next, we configure apt to prioritize the .deb version of Firefox:
$ echo '
Package: *
Pin: release o=LP-PPA-mozillateam
Pin-Priority: 1001
Package: firefox
Pin: version 1:1snap1-0ubuntu2
Pin-Priority: -1
' | sudo tee /etc/apt/preferences.d/mozilla-firefox
Now, we remove the Snap version of Firefox:
$ sudo snap remove firefox
Finally, we update the package cache and install Firefox as .deb:
$ sudo apt update && sudo apt install -y firefox
Once Firefox installs, let’s confirm that the geckodriver binary is usable:
$ geckodriver --version
geckodriver 0.33.0 ( 2023-11-06)
2.2. RHEL, Fedora and CentOS Stream
On RHEL, geckodriver is available under the canonical name firefox-geckodriver:
$ sudo yum install -y firefox-geckodriver
Besides geckodriver, it also pulls the Firefox browser as a dependency. In addition, on Fedora and CentOS Stream, geckodriver binary is installed as part of the recent versions of Firefox:
$ sudo dnf install -y firefox
2.3. Arch and Manjaro
On Arch and Arch-derivatives, we use pacman to install the package:
$ sudo pacman -S --noconfirm geckodriver
3. GitHub Repository
Alternatively, we can install geckodriver from its official GitHub repository. The latest version is available in the “Releases” section, where we can pick the appropriate installer for our system.
For our example, we pick the linux64 build:
$ curl -LO "https://github.com/mozilla/geckodriver/releases/download/v0.33.0/geckodriver-v0.33.0-linux64.tar.gz"
Now, let’s extract the archive to the conventional /opt directory:
$ sudo mkdir /opt/geckodriver && \
tar -xvf geckodriver-v0.33.0-linux64.tar.gz -C /opt/geckodriver
Now, we simply add it to $PATH:
$ echo 'export PATH="/opt/geckodriver:$PATH"' >> ~/.bashrc
Let’s test it out:
$ geckodriver --version
geckodriver 0.33.0 (a80e5fd61076 2023-04-02 18:31 +0000)
4. Compiling From Sources
Most of the time, the previous methods should suffice. However, if they aren’t feasible, we simply compile geckodriver from the source for our target platform.
4.1. Building From crates.io
The most straightforward way to download, compile, and install geckodriver is by utilizing cargo. cargo is part of the Rust toolchain, which we can install using rustup or from the official package repository:
$ sudo apt install -y cargo
cargo has a central package repository known as crates.io. So, we simply use cargo to download the geckodriver crate from it and build it:
$ cargo install geckodriver
We should keep in mind that it takes quite a while for the Rust source code to build.
4.2. Building Manually
For the more elite, we can also compile geckodriver the classic way. For that, we need the Rust toolchain:
$ sudo apt install -y cargo rustc
Alternatively, if we prefer the newer version of the toolchain we can use rustup.rs:
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
default host triple: x86_64-unknown-linux-gnu
default toolchain: stable (default)
profile: default
modify PATH variable: yes
1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
> 1
Here, we proceed with the default selections. Once it’s installed, let’s verify it:
$ cargo --version
cargo 1.74.0 (ecb9851af 2023-10-18)
Next, we need mercurial, which is a performant Distributed Version Control System (DVCS):
$ sudo apt install mercurial
Now, we clone the repository:
$ hg clone https://hg.mozilla.org/mozilla-central
Afterward, we cd into the geckodriver repository:
$ cd mozilla-central/testing/geckodriver
We build the source in this directory using cargo:
$ cargo build .
It fetches all the necessary dependencies specified in the Cargo.toml file, builds the source, and creates an executable in the bin directory.
5. Shell Script Automation
To make our life easier, we can write a simple shell script that downloads and installs the latest version of geckodriver:
#!/bin/bash
rm -rf ./geckodriver
INSTALL_DIR="/usr/local/bin"
GECKO_URL="https://api.github.com/repos/mozilla/geckodriver/releases/latest"
TARGET_PLATFORM="linux64"
json=$(curl -s "$GECKO_URL")
url=$(echo "$json" | jq -r --arg TARGET_PLATFORM "$TARGET_PLATFORM" '.assets[].browser_download_url | select(contains($TARGET_PLATFORM) and endswith("gz"))')
[ -z "$url" ] && echo "Error: Couldn't find the download URL. && exit 1
curl -s -L "$url" | tar -xz
chmod +x geckodriver
[ ! -w "$INSTALL_DIR" ] && echo "Error: Permission denied." && exit 1
sudo mv geckodriver "$INSTALL_DIR" && \
echo "Success: $INSTALL_DIR/geckodriver"
The script fetches the JSON for geckodriver. We parse the JSON using jq and pick the latest version for our target platform. Of course, we can change $TARGET_PLATFORM if we need to.
Once the binary is downloaded, we install it to $INSTALL_DIR.
6. Conclusion
In this article, we learned the different ways to install geckodriver on Linux. We saw how to install geckodriver from package repositories as well as the GitHub repository.
In addition, we also learned how to compile geckodriver from source for our target platform, if there are no pre-built binaries for it.
Finally, we wrote a simple shell script that automates the process of downloading and installing the latest version of geckodriver from its official GitHub repository.