How to Install Selenium Tool in Linux

Selenium are tool used by developers and testers to automate tasks in web browsers. If you’re working in Linux and want to use Selenium tools for browser automation then you have to install it first.

Table of Contents

Prerequisites to Install Selenium Tools in Linux

  • Java – Required to run Selenium.
  • Google Chrome – A browser for testing.
  • ChromeDriver – Connects Selenium to Chrome.
  • Selenium JAR Files – The main Selenium software.

Steps to Install Selenium Tools on Linux

Step 1: Install Java in Linux

Selenium requires Java to work. Follow these steps to install Java on your Linux system:

You can skip the step if Java is already installed in Linux.

Update your system before Java installation:

sudo apt update
Install Java:
sudo apt install openjdk-11-jdk -y
install java in linux

Step 2: Install Google Chrome

Google Chrome is the browser Selenium will automate. To install it we need to download the Chrome package first:

wget -N https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -O /tmp/google-chrome-stable_current_amd64.deb
install google chrome in linux

Install Chrome:

after the Chrome package download, we need to install the package

sudo apt install -y /tmp/google-chrome-stable_current_amd64.deb

Step 3: Install ChromeDriver

Now, we need to install ChromeDriver in Linux as ChromeDriver allows Selenium to control Google Chrome.

Check your Chrome version:
google-chrome --version

Go to the ChromeDriver download page and download the version that matches your Chrome version.

Alternatively, use this command (replace ${version} with your Chrome version):

wget -N https://chromedriver.storage.googleapis.com/${version}/chromedriver_linux64.zip -O /tmp/chromedriver_linux64.zip
download chromedriver in linux
Install ChromeDriver:
unzip /tmp/chromedriver_linux64.zip -d /tmp/chromedriver/
sudo cp /tmp/chromedriver/chromedriver /usr/local/bin/chromedriver
chromedriver -v
install chromedriver in linux

Step 4: Download Selenium JAR Files

The Selenium JAR file is the main software used for Selenium.

Download the Selenium server file:
wget https://github.com/SeleniumHQ/selenium/releases/download/selenium-4.11.0/selenium-server-4.11.0.jar -O selenium-server.jar
download selenium jar files in linux

Step 5: Run Selenium with Chrome

Now that everything is set up, let’s run Chrome using Selenium.

-Install the xvfb utility (used to run Chrome in the background):

sudo apt install xvfb -y
run selenium with chrome
Start the Selenium server with Chrome:
xvfb-run java -Dwebdriver.chrome.driver=/usr/bin/chromedriver -jar selenium-server.jar

By following these steps, you have successfully installed and configured Selenium on a Linux system. To automate web browser tasks, you now have all the necessary components, including Java, Google Chrome, ChromeDriver, and the Selenium JAR files. With Selenium properly set up, you can start writing and executing test scripts to automate browser interactions in Chrome. This setup is essential for developers and testers looking to streamline web testing and automate repetitive tasks efficiently.

Leave a Comment