116

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?

uvasal
  • 513
mySun
  • 1,971

6 Answers6

169

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.

Addison
  • 306
Steven Stip
  • 1,900
  • 104
    Step 4 can be changed to sudo mv geckodriver /usr/local/bin/ – Tulio Casagrande Jun 03 '17 at 17:29
  • 3
    Thanks @TulioCasagrande. Step 4 did not work for me but your command did. – Just In Time Berlake Jun 05 '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 08 '18 at 13:00
  • note: $PATH should contains a directory such as /usr/local/bin. Don't put an executable such as /path/to/geckodriver there. – jfs Feb 18 '18 at 18:05
  • 1
    I have done everything right but forgot to install Firefox :-) If that is the case just run: sudo apt-get install firefox – Wojciech Jakubas 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 00:09
  • 1
    In case anyone else is as stupid as me, remember not to literally export the path "/path-to-extracted-file/.". I wonder if that's why other people reported that step 4 didin't work for them. :/ – Ram Apr 29 '19 at 00:14
  • 1
    In case you are using with Selenium, make sure that the versions of the geckodriver and Selenium are compatible. – specstr May 01 '22 at 16:01
  • @TulioCasagrandeAlberto this one is great , much better than any other solution!!! – Manishyadav Jun 07 '22 at 11:50
32

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") and endswith("gz"))') curl -s -L "$url" | tar -xz chmod +x geckodriver sudo mv geckodriver "$INSTALL_DIR" echo "installed geckodriver binary in $INSTALL_DIR"

Corey Goldberg
  • 3,046
  • 3
  • 19
  • 21
  • 6
    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 04 '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
Sandeep
  • 590
  • 4
  • 5
  • 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. – Juuso Ohtonen Mar 22 '18 at 05: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 06 '21 at 12:41
4

On Ubuntu 22.04, it seems that geckodriver is now installed when you install Firefox:

$ sudo apt install firefox 

It seems that the old firefox-geckodriver package has been dropped.

  • Thank you, I added your comment to my answer, but saw you made your own answer as well. if you want me to remove it please say so! – Mister Verleg Nov 30 '22 at 09:24
  • 1
    @MisterVerleg No problem at all. Let's leave both your answer and my answer up and let the sorting/ranking system take care of the rest. Seems like the easiest approach :) – countermeasure Nov 30 '22 at 10:16
3

If you use the command line pre ubuntu 2.04:

sudo apt-get install firefox-geckodriver

Thanks to the comment of @countermeasure:

apparently installing firefox will also install gecko driver

sudo apt install firefox 
  • In fact this worked at the time but the package is no longer available on latest Ubuntu versions, as mentioned by @countermeasure in the question comments. – baptx Nov 29 '22 at 22:04
  • 1
    On Ubuntu 22.04, it seems that sudo apt install firefox will also install geckodriver. I'm guessing that might be why the firefox-geckodriver package was dropped. – countermeasure Nov 30 '22 at 08:54
1

There are essentially three steps:

  1. download a release from github
  2. unzip into the right directory, namely usr/local/bin (can be merged into one line!)
  3. set executable permissions. These steps should work for any Linux distribution (worked on my Debian 10). Here is the shell code:
wget https://github.com/mozilla/geckodriver/releases/download/v0.33.0/geckodriver-v0.33.0-linux64.tar.gz
sudo tar -xzvf geckodriver*tar.gz -C /usr/local/bin
sudo chmod +x /usr/local/bin/geckodriver

As for newest versions of Ubuntu, it can be installed with sudo apt-get install firefox. Older versions accept sudo apt-get install firefox-geckodriver.

Package firefox-geckodriver is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
  firefox