Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install Chrome, ChromeDriver and Selenium on Ubuntu 16.04
#!/usr/bin/env bash
# https://developers.supportbee.com/blog/setting-up-cucumber-to-run-with-Chrome-on-Linux/
# https://gist.github.com/curtismcmullan/7be1a8c1c841a9d8db2c
# https://stackoverflow.com/questions/10792403/how-do-i-get-chrome-working-with-selenium-using-php-webdriver
# https://stackoverflow.com/questions/26133486/how-to-specify-binary-path-for-remote-chromedriver-in-codeception
# https://stackoverflow.com/questions/40262682/how-to-run-selenium-3-x-with-chrome-driver-through-terminal
# https://askubuntu.com/questions/760085/how-do-you-install-google-chrome-on-ubuntu-16-04
# Versions
CHROME_DRIVER_VERSION=`curl -sS https://chromedriver.storage.googleapis.com/LATEST_RELEASE`
SELENIUM_STANDALONE_VERSION=3.9.1
SELENIUM_SUBDIR=$(echo "$SELENIUM_STANDALONE_VERSION" | cut -d"." -f-2)
# Remove existing downloads and binaries so we can start from scratch.
sudo apt-get remove google-chrome-stable
rm ~/selenium-server-standalone-*.jar
rm ~/chromedriver_linux64.zip
sudo rm /usr/local/bin/chromedriver
sudo rm /usr/local/bin/selenium-server-standalone.jar
# Install dependencies.
sudo apt-get update
sudo apt-get install -y unzip openjdk-8-jre-headless xvfb libxi6 libgconf-2-4
# Install Chrome.
sudo curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add
sudo echo "deb https://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list
sudo apt-get -y update
sudo apt-get -y install google-chrome-stable
# Install ChromeDriver.
wget -N https://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip -P ~/
unzip ~/chromedriver_linux64.zip -d ~/
rm ~/chromedriver_linux64.zip
sudo mv -f ~/chromedriver /usr/local/bin/chromedriver
sudo chown root:root /usr/local/bin/chromedriver
sudo chmod 0755 /usr/local/bin/chromedriver
# Install Selenium.
wget -N https://selenium-release.storage.googleapis.com/$SELENIUM_SUBDIR/selenium-server-standalone-$SELENIUM_STANDALONE_VERSION.jar -P ~/
sudo mv -f ~/selenium-server-standalone-$SELENIUM_STANDALONE_VERSION.jar /usr/local/bin/selenium-server-standalone.jar
sudo chown root:root /usr/local/bin/selenium-server-standalone.jar
sudo chmod 0755 /usr/local/bin/selenium-server-standalone.jar
#!/usr/bin/env bash
# Run Chrome via Selenium Server
start-chrome() {
xvfb-run java -Dwebdriver.chrome.driver=/usr/local/bin/chromedriver -jar /usr/local/bin/selenium-server-standalone.jar
}
start-chrome-debug() {
xvfb-run java -Dwebdriver.chrome.driver=/usr/local/bin/chromedriver -jar /usr/local/bin/selenium-server-standalone.jar -debug
}
# Run Chrome Headless
start-chrome-headless() {
chromedriver --url-base=/wd/hub
}
# Start
# start-chrome
# start-chrome-debug
# start-chrome-headless
@Mranaliny
Copy link

Mranaliny commented Feb 8, 2019

Hey I am getting permission denied error : -bash: /etc/apt/sources.list.d/google-chrome.list: Permission denied
when I hit this command
sudo echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list

@nshores
Copy link

nshores commented Apr 8, 2019

Just wanted to let you guys know, that this is now working again when using the latest version of selenium.

@davidmukiibi
Copy link

davidmukiibi commented Sep 20, 2019

nice work here... but I can not seem to gracefullyy tell selenium to release the terminal for me to run my tests... how do I do that... this is my command
sudo DISPLAY=:1 xvfb-run java -Dwebdriver.chrome.driver=/usr/bin/google-chrome -Dwebdriver.chrome.whitelistedIps="localhost,127.0.0.1,192.168.*.*" -jar selenium-server-standalone-3.13.0.jar -debug && npm run test-e2e

@mobinalhassan
Copy link

mobinalhassan commented Oct 30, 2019

I'm new to use linux tell me how to install .sh files?

@davidmukiibi
Copy link

davidmukiibi commented Oct 30, 2019

@Tuan-Kirie
Copy link

Tuan-Kirie commented Dec 15, 2019

Thank you my friend

@romaHerman
Copy link

romaHerman commented Feb 24, 2020

Thank you!

@obovsunivskyii
Copy link

obovsunivskyii commented Feb 25, 2020

when I'm executing this sudo curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add
getting : This command can only be used by root.
I'm already in the root. Any suggestions?

@davidmukiibi
Copy link

davidmukiibi commented Feb 26, 2020

@obovsunivskyii
Copy link

obovsunivskyii commented Feb 26, 2020

@davidmukiibi same result.

@jayzsuarez
Copy link

jayzsuarez commented Mar 17, 2020

hi All,

I need to update my version of chromedriver in Ubuntu.

a) Updated version in /usr/bin/chromedriver
image

Then when running on my Jenkins it still using the old version installed 2.41
image

image

@mobinalhassan
Copy link

mobinalhassan commented Mar 18, 2020

There are to place where from chromeDriver runs..
1:
which python
output will be (if you are using pycharm or anaconda)
/home/user/anaconda3/bin/python
so you need to put ChromeDrive file in this directory: /usr/local/bin
otherwise: /usr/bin
you can put ChromeDrive file manual to these path and I suggest to use (79.0) version
https://chromedriver.chromium.org/downloads

@manjotsk
Copy link

manjotsk commented Apr 7, 2020

Thankyou :)

@alinoudev
Copy link

alinoudev commented Jun 13, 2020

Thanks!

@wbrgss
Copy link

wbrgss commented Aug 13, 2020

very nice, ty

@mohank28
Copy link

mohank28 commented Sep 3, 2020

Thank you!

Taking into consider the following permission:

chown root:root /usr/local/share/chromedriver

@Ruslan-Skira
Copy link

Ruslan-Skira commented Nov 9, 2020

Hello catch this erorr all the time selenium.common.exceptions.WebDriverException: Message: unknown error: DevToolsActivePort file doesn't exist

@SerheyDolgushev
Copy link

SerheyDolgushev commented Nov 26, 2020

-Dwebdriver.chrome.logfile=chrome.log parameter might be useful if you want to check the chrome logs:

xvfb-run java -Dwebdriver.chrome.logfile=chrome.log -Dwebdriver.chrome.driver=/usr/local/bin/chromedriver -jar /usr/local/bin/selenium-server-standalone.jar

@timartinelli
Copy link

timartinelli commented Dec 13, 2020

this is a very good friend.

@Ruslan-Skira
Copy link

Ruslan-Skira commented Dec 15, 2020

-Dwebdriver.chrome.logfile=chrome.log parameter might be useful if you want to check the chrome logs:

xvfb-run java -Dwebdriver.chrome.logfile=chrome.log -Dwebdriver.chrome.driver=/usr/local/bin/chromedriver -jar /usr/local/bin/selenium-server-standalone.jar

Thank you @SerheyDolgushev

@logbasex
Copy link

logbasex commented Apr 9, 2021

You can get the latest version of selenium as following

SELENIUM_STANDALONE_JAR=`curl https://selenium-release.storage.googleapis.com | xq | jq 'last(.ListBucketResult|.Contents|.[]|.Key| select(test(".*selenium-server-standalone.*.jar")))`

wget -N https://selenium-release.storage.googleapis.com/$SELENIUM_STANDALONE_JAR -P ~/

@IamRabbbi
Copy link

IamRabbbi commented Apr 16, 2021

Thank you!!

@leoapost
Copy link

leoapost commented Apr 28, 2021

Very helpful, thanks!

@AndrejHyben
Copy link

AndrejHyben commented May 7, 2021

GREAT JOB - HELPED US 5 minutes before 12 :) ... I'll share this article in my networks. ... thank you

@nancyrathore92
Copy link

nancyrathore92 commented May 25, 2021

Thank you so much man!!

@system-ini
Copy link

system-ini commented Jul 1, 2021

Very grateful!)

@hanjuangxyz
Copy link

hanjuangxyz commented Sep 13, 2021

This helps me a lot. Thank you.

@sandeshmms
Copy link

sandeshmms commented Sep 15, 2021

I am using AWS EC2 Ubuntu instance and I am getting java.lang.IllegalStateException: The driver executable must exist: /usr/local/bin/chromedriver. Any idea how to resolve it ? I have also made the chromedriver as executable using sudo chown root:root /usr/local/bin/chromedriver and sudo chmod 0755 /usr/local/bin/chromedriver and sudo chmod 777 /usr/local/bin/chromedriver. Also, my driver is placed at /usr/local/bin which is part of Ubuntu's PATH variable. Can you plesse guide me because I am stuck with this for the past few days and no solution yet.

@manjotsk
Copy link

manjotsk commented Sep 16, 2021

@sandeshmms Can you please share the stack trace? Mostly it is due to the wrong path specified in web driver properties, or the wrong property key!

@sandeshmms
Copy link

sandeshmms commented Sep 17, 2021

@manjotsk:
Below is the stack trace:
32101 [ERROR] testing.TC_003.bmeth[org.testng.TestRunner@6fcd2e32, org.testng.xml.XmlTest@5f8b73c7, public void testing.TC_003.uabc() throws java.lang.InterruptedException, Ljava.lang.Object;@28e4e9e1, [TestResult name={null} status=CREATED method=TC_003.uabc()[pri:0, instance:testing.TC_003@432038ec] output={null}] Time elapsed: 1.758 s <<< FAILURE!
java.lang.IllegalStateException: The driver executable must exist: /usr/local/bin/chromedriver

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