Skip to content

Instantly share code, notes, and snippets.

@cgoldberg
Last active August 18, 2023 10:20
Show Gist options
  • Save cgoldberg/4097efbfeb40adf698a7d05e75e0ff51 to your computer and use it in GitHub Desktop.
Save cgoldberg/4097efbfeb40adf698a7d05e75e0ff51 to your computer and use it in GitHub Desktop.
download and install latest geckodriver for linux or mac (selenium webdriver)
#!/bin/bash
# download and install latest geckodriver for linux or mac.
# required for selenium to drive a firefox browser.
install_dir="/usr/local/bin"
json=$(curl -s https://api.github.com/repos/mozilla/geckodriver/releases/latest)
if [[ $(uname) == "Darwin" ]]; then
url=$(echo "$json" | jq -r '.assets[].browser_download_url | select(contains("macos"))')
elif [[ $(uname) == "Linux" ]]; then
url=$(echo "$json" | jq -r '.assets[].browser_download_url | select(contains("linux64"))')
else
echo "can't determine OS"
exit 1
fi
curl -s -L "$url" | tar -xz
chmod +x geckodriver
sudo mv geckodriver "$install_dir"
echo "installed geckodriver binary in $install_dir"
@miken
Copy link

miken commented Sep 6, 2020

I had trouble with the original script - @brunoao86's script works.

@ktnoc
Copy link

ktnoc commented Jan 4, 2021

import json
import requests
import platform
import sys
import tarfile
import urllib
import os
latest_release = requests.get("https://api.github.com/repos/mozilla/geckodriver/releases/latest")
host_version = "linux"+platform.architecture()[0][:2]
for version in latest_release.json()['assets']:
    if host_version in version['name'] and ".asc" not in version['name']:
        local_filename, headers = urllib.request.urlretrieve(version['browser_download_url'])
        tarfile.open(local_filename).extractall(os.path.dirname(sys.executable))
        urllib.request.urlcleanup()

installs on virtualenv of the executed script

@MichaelCurrin
Copy link

@DonFruendo
Copy link

A different version of the script modification provided by @brunoao86, that I use is to utilize jq further and dropping the asc urls right in the search. See below for the full script

#!/bin/bash
# download and install latest geckodriver for linux or mac.
# required for selenium to drive a firefox browser.

install_dir="/usr/local/bin"
json=$(curl -s https://api.github.com/repos/mozilla/geckodriver/releases/latest)
if [[ $(uname) == "Darwin" ]]; then
    url=$(echo "$json" | jq -r '.assets[].browser_download_url | select(contains("macos")) | select(contains("asc") | not)')
elif [[ $(uname) == "Linux" ]]; then
    url=$(echo "$json" | jq -r '.assets[].browser_download_url | select(contains("linux64")) | select(contains("asc") | not)')
else
    echo "can't determine OS"
    exit 1
fi
curl -s -L "$url" | tar -xz
chmod +x geckodriver
sudo mv geckodriver "$install_dir"
echo "installed geckodriver binary in $install_dir"

@geoashis
Copy link

Will the latest version of geckodriver driver work with the latest version of firefox-esr at any point in time?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment