98

I use Selenium in Python, I tried to run the webdriver function:

default_browser = webdriver.Firefox()

This Exception:

WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

geckodriver in this site: https://github.com/mozilla/geckodriver

But how to install in Ubuntu 16.04 and can I fix this?

3
  • 1
    download , extract and add it to $PATH Jan 11 '17 at 17:42
  • Hi @rajeevmaash , Please fully explain, Thank you so much.
    – mySun
    Jan 11 '17 at 20:15
  • 1
    sudo apt-get install firefox-geckodriver Dec 6 '19 at 14:02
147

Here are the steps:

  1. Go to the geckodriver releases page. Find the latest version of the driver for your platform and download it. For example:

    wget https://github.com/mozilla/geckodriver/releases/download/v0.24.0/geckodriver-v0.24.0-linux64.tar.gz
    
  2. Extract the file with:

    tar -xvzf geckodriver*
    
  3. Make it executable:

    chmod +x geckodriver
    
  4. Add the driver to your PATH so other tools can find it:

    export PATH=$PATH:/path-to-extracted-file/.
    

There are many ways to do this that will work. The above works for me on Ubuntu 16.10 64-bit.

7
  • 87
    Step 4 can be changed to sudo mv geckodriver /usr/local/bin/ Jun 3 '17 at 17:29
  • 2
    Thanks @TulioCasagrande. Step 4 did not work for me but your command did. Jun 5 '17 at 19:10
  • 1
    There is firefoxdriver 3.8.0 package in Ubuntu Bionic, but it doesn't contain geckodriver, so doesn't work yet. The 2.x versions of these packages were able to launch Firefox, but weren't able to do anything.
    – Velkan
    Feb 8 '18 at 13:00
  • 1
    I have done everything right but forgot to install Firefox :-) If that is the case just run: sudo apt-get install firefox Oct 12 '18 at 22:46
  • 1
    Step 3 is redundant, we're downloading a gunzip not a zip file
    – lamino
    Dec 27 '18 at 0:09
25

Manual steps to install geckodriver on Ubuntu:

  • visit https://github.com/mozilla/geckodriver/releases
  • download the latest version of "geckodriver-vX.XX.X-linux64.tar.gz"
  • unarchive the tarball (tar -xvzf geckodriver-vX.XX.X-linux64.tar.gz)
  • give executable permissions to geckodriver (chmod +x geckodriver)
  • move the geckodriver binary to /usr/local/bin or any location on your system PATH.

Script to install geckodriver on Ubuntu:

#!/bin/bash

INSTALL_DIR="/usr/local/bin"

json=$(curl -s https://api.github.com/repos/mozilla/geckodriver/releases/latest)
url=$(echo "$json" | jq -r '.assets[].browser_download_url | select(contains("linux64"))')
curl -s -L "$url" | tar -xz
chmod +x geckodriver
sudo mv geckodriver "$INSTALL_DIR"
echo "installed geckodriver binary in $INSTALL_DIR"
3
  • 3
    I didn't go through - had my own script - but this kind of serious scripting, using jq and avoiding at most hardcoded things should always be upvoted.
    – ribamar
    Sep 4 '18 at 12:50
  • 1
    I like how you have used jq in the script to get the target URL
    – NurShomik
    Oct 26 '18 at 18:29
  • I installed it like this, thanks it works smoothly, then tested as a command, and that works. But then I run selenium in the python script, and it raises the same exception: selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
    – miguelfg
    Jan 25 '19 at 18:45
24

Webdriver installation (silent mode) that can be used in sysadmin scripts (bash/ansible).

## Geckodriver
wget https://github.com/mozilla/geckodriver/releases/download/v0.23.0/geckodriver-v0.23.0-linux64.tar.gz
sudo sh -c 'tar -x geckodriver -zf geckodriver-v0.23.0-linux64.tar.gz -O > /usr/bin/geckodriver'
sudo chmod +x /usr/bin/geckodriver
rm geckodriver-v0.23.0-linux64.tar.gz

## Chromedriver
wget https://chromedriver.storage.googleapis.com/2.29/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
sudo chmod +x chromedriver
sudo mv chromedriver /usr/bin/
rm chromedriver_linux64.zip
2
  • Thanks. It seems that geckodriver version 0.16.1 is compatible with FF 52.4.0 (on Debian jessie) – geckodriver version 0.19 was not. Mar 22 '18 at 5:44
  • I prefer this over the fully automated script for my use case. First, it doesn't use jq which I don't have installed on my system. Second, it always installs a known version that I can test and verify works correctly for me.
    – poleguy
    Jul 6 at 12:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.