Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
this worked to install selenium and google chrome on my Ubuntu 16 server.
#!/usr/bin/env bash
# used to install offical chrome and selenium on Ubuntu 16.04.1 LTS, 18.04, 20.04.1 LTS desktop, Jan 2021
# also tested and works on Elem OS 5.1 :)
#
# make sure script is run as root or sudo
if [[ $(whoami) != "root" ]] ; then
echo ; echo "This script, $0, SHOULD be run as ROOT. " ; echo
exit 1
fi
#
cd ~
sudo apt-get update
sudo apt install python-pip
pip install simplejson
pip install bs4
pip install selenium
sudo apt-get install -y libasound2 libnspr4 libnss3 libxss1 xdg-utils unzip libappindicator1 fonts-liberation
apt-get -f install
wget http://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome*.deb
# chromedriver also needs to be installed.
CHROME_VERSION=$(curl https://chromedriver.storage.googleapis.com/LATEST_RELEASE)
wget https://chromedriver.storage.googleapis.com/$CHROME_VERSION/chromedriver_linux64.zip
#wget http://chromedriver.storage.googleapis.com/2.45/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
sudo mv chromedriver /usr/bin/chromedriver
sudo chown root:root /usr/bin/chromedriver # questionable - may need to add other user permissions
sudo chmod +x /usr/bin/chromedriver
@LoganGray
Copy link
Author

LoganGray commented Jan 14, 2020

when testing on ubuntu 18.04 desktop.... noticed it wouldn't allow wget via https to grab google-chrome-stable_current_amd64.deb.. very odd.

So I changed it to NOT use SSL and it worked fine.

@Entretoize
Copy link

Entretoize commented Mar 26, 2020

Perfect thanks !

@LoganGray
Copy link
Author

LoganGray commented Apr 10, 2020

chrome_version added to deal with the crazy F%^&*( versioning of chrome and chromedriver. What a PIA!

@ozbillwang
Copy link

ozbillwang commented Aug 13, 2020

Thanks.

Seems we need install more dependency packages now

RUN apt-get install -y libappindicator3-1 libatk-bridge2.0-0 libatspi2.0-0 libgbm1 libgtk-3-0

Here is whole Dockerfile I used.

FROM openjdk:8u232

# chrome-browser
RUN apt-get update
RUN apt-get install -y wget
RUN apt-get install -y libasound2 libnspr4 libnss3 libxss1 xdg-utils unzip
RUN apt-get install -y libappindicator1 fonts-liberation
RUN apt-get install -y libappindicator3-1 libatk-bridge2.0-0 libatspi2.0-0 libgbm1 libgtk-3-0
RUN apt-get install -f
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN dpkg -i google-chrome*.deb

The part to install python and pip packages in your steps are not required and I can wget the chrome package via https without issue.

@Tylersuard
Copy link

Tylersuard commented Aug 28, 2020

YOU, SIR, are a gentleman and a scholar.

@aborruso
Copy link

aborruso commented Dec 5, 2020

@LoganGray thank you very much.

After installing it, how to use chrome via cli in headless mode? What's the name of the command?

@LoganGray
Copy link
Author

LoganGray commented Jan 8, 2021

Thanks.

Seems we need install more dependency packages now

RUN apt-get install -y libappindicator3-1 libatk-bridge2.0-0 libatspi2.0-0 libgbm1 libgtk-3-0

Here is whole Dockerfile I used.

FROM openjdk:8u232

# chrome-browser
RUN apt-get update
RUN apt-get install -y wget
RUN apt-get install -y libasound2 libnspr4 libnss3 libxss1 xdg-utils unzip
RUN apt-get install -y libappindicator1 fonts-liberation
RUN apt-get install -y libappindicator3-1 libatk-bridge2.0-0 libatspi2.0-0 libgbm1 libgtk-3-0
RUN apt-get install -f
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN dpkg -i google-chrome*.deb

The part to install python and pip packages in your steps are not required and I can wget the chrome package via https without issue.

Interesting! However, this was not intended to be used in a docker file but for a Ubuntu server VPS or otherwise.

However, I will check if today if any mods need to be made to get it to work on Ubuntu 20, and
if I have time -
maybe a docker container as well. ;)

@LoganGray
Copy link
Author

LoganGray commented Jan 8, 2021

@LoganGray thank you very much.

After installing it, how to use chrome via cli in headless mode? What's the name of the command?

Hi. I believe I was using Selenium at the time - or was it Puppeteer? but anyway, I could actually expand on this a bit, and turn this into a full repo with examples if you like. I was trying to keep things very simple here and just do a single bash script - but if you'd like me to show a bit more, just let me know.

@mr-bat
Copy link

mr-bat commented Nov 24, 2021

sudo apt install python-pip should be changed to sudo apt install -y python3-pip. python-pip does not exist on Ubuntu 20.04.

@Abiruth
Copy link

Abiruth commented Jun 7, 2022

Genius thank you!!

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