Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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"
@yogesh-desai

This comment has been minimized.

Copy link

yogesh-desai commented Sep 12, 2017

Thank you. 👍

@diemol

This comment has been minimized.

Copy link

diemol commented Oct 9, 2017

Hi, thanks for this script! Very helpful.

I copied and used it for Chromedriver as well, here it is:

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

install_dir="/usr/local/bin"
version=$(wget -qO- https://chromedriver.storage.googleapis.com/LATEST_RELEASE)
if [[ $(uname) == "Darwin" ]]; then
    url=https://chromedriver.storage.googleapis.com/$version/chromedriver_mac64.zip
elif [[ $(uname) == "Linux" ]]; then
    url=https://chromedriver.storage.googleapis.com/$version/chromedriver_linux64.zip
else
    echo "can't determine OS"
    exit 1
fi
curl -s -L "$url" | tar -xz
chmod +x chromedriver
sudo mv chromedriver "$install_dir"
echo "installed chromedriver binary in $install_dir"

I'll create a gist with both and quote you as the source, thanks!

EDIT: Here is the gist https://gist.github.com/diemol/635f450672b5bf80420d595ca0016d20

@zhisme

This comment has been minimized.

Copy link

zhisme commented Feb 2, 2018

Before I could run this script, I had to install jq.
brew install jq
macos. System version.

Darwin MacBook-zh.local 16.6.0 Darwin Kernel Version 16.6.0: Fri Apr 14 16:21:16 PDT 2017; 
root:xnu-3789.60.24~6/RELEASE_X86_64 x86_64

FYI:
read article

@ORESoftware

This comment has been minimized.

Copy link

ORESoftware commented Feb 11, 2018

@cgoldberg

put set -e; at the top of your bash scripts

@maxpeterson

This comment has been minimized.

Copy link

maxpeterson commented Apr 18, 2018

You could also use Python:

url=$(curl -s https://api.github.com/repos/mozilla/geckodriver/releases/latest | python -c "import sys, json; print(next(item['browser_download_url'] for item in json.load(sys.stdin)['assets'] if 'linux64' in item.get('browser_download_url', '')))")
@Jambon1510

This comment has been minimized.

Copy link

Jambon1510 commented Jun 23, 2018

This is not working for me, url return is empty

uname 
Linux

bash -x ./geckodriver-install.sh
.......
+ url=
+ tar -xz
+ curl -s -L ''

gzip: stdin: unexpected end of file
tar: Child returned status 1
tar: Error is not recoverable: exiting now
+ chmod +x geckodriver
chmod: cannot access 'geckodriver': No such file or directory
+ sudo mv geckodriver /usr/local/bin
mv: cannot stat 'geckodriver': No such file or directory
+ echo 'installed geckodriver binary in /usr/local/bin'
installed geckodriver binary in /usr/local/bin

@Kogam22

This comment has been minimized.

Copy link

Kogam22 commented Jul 20, 2018

Working in Ubuntu 18.04.
sudo apt install jq was necessary.

@Jambon1510 :

This is not working for me, url return is empty.

Well, you might be on a 32-bit machine. Try changing linux64 in this line :
10 : url=$(echo "$json" | jq -r '.assets[].browser_download_url | select(contains("linux64"))')
to linux32.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.