In this article, we will guide you through the process of adding Chromedriver to the PATH in Ubuntu 18.04. This is a crucial step when setting up Selenium WebDriver with Chrome, as it allows your script to interface with the Chrome browser.
What is Chromedriver?
Chromedriver is a standalone server that implements WebDriver’s wire protocol for Chrome. It comes in an executable form and communicates with the Chrome browser by driving it as a user would.
Before we can add Chromedriver to the PATH, we need to download it. You can download the Chromedriver that matches your installed Chrome version from the Chromedriver download page.
Once you’ve downloaded Chromedriver, extract it to a known location on your system. For example, you could extract it to your Documents folder:
unzip ~/Downloads/chromedriver_linux64.zip -d ~/Documents/Python/
This command uses the
unzip utility to extract the downloaded Chromedriver zip file (
chromedriver_linux64.zip) to the
Adding Chromedriver to the PATH
There are several ways to add Chromedriver to the PATH in Ubuntu. We’ll cover three options in this article.
Option A: Move Chromedriver to a Directory Already in PATH
The simplest way to add Chromedriver to the PATH is to move it to a directory that is already included in the PATH.
/usr/local/bin is a common choice for this:
sudo mv ~/Documents/Python/chromedriver /usr/local/bin
This command uses
sudo to run the
mv command with root privileges, as modifying the contents of
/usr/local/bin typically requires such privileges. The
mv command moves the
chromedriver executable from its current location to
Next, you need to make the Chromedriver executable:
sudo chmod +x /usr/local/bin/chromedriver
chmod command changes the permissions of files. The
+x option makes the file executable.
Option B: Save Chromedriver at a Custom Location and Add it to PATH
If you prefer to keep Chromedriver in a custom location, you can add that location to the PATH:
echo 'export PATH="$HOME/Documents/Python/ChromeDriver:$PATH"' >> ~/.profile
echo command adds a line to the end of the
~/.profile file that exports your custom directory as part of the PATH. The
source command applies the changes to the current session.
Option C: Save Chromedriver at a Custom Location and Create a Symlink
A third option is to save Chromedriver at a custom location and create a symbolic link (or symlink) to it in a directory that is already in PATH:
sudo ln -s ~/Documents/Python/ChromeDriver/chromedriver /usr/local/bin/chromedriver
ln command creates a symbolic link. The
-s option specifies that a symbolic link should be created. This command creates a symbolic link at
/usr/local/bin/chromedriver that points to the
chromedriver executable in your custom directory.
Adding Chromedriver to the PATH in Ubuntu 18.04 is a straightforward process. Whether you choose to move Chromedriver to a directory already in PATH, add a custom directory to the PATH, or create a symlink, each method has its own advantages. Choose the one that best suits your needs.
Adding Chromedriver to the PATH allows your script to interact with the Chrome browser when using Selenium WebDriver. It enables the script to locate and control the Chrome browser for automated testing or web scraping.
You can download Chromedriver for Ubuntu 18.04 from the Chromedriver download page. Make sure to choose the version that matches your installed Chrome browser version.
Yes, you can add Chromedriver to any directory in the PATH. However, it is recommended to add it to a directory that is already included in the PATH, such as
/usr/local/bin, for easier access and compatibility with other applications.
To make Chromedriver executable, you can use the
chmod command. For example, you can run
sudo chmod +x /usr/local/bin/chromedriver to make the Chromedriver executable after moving it to
Yes, you can keep Chromedriver in a custom location of your choice. You can add the custom directory to the PATH by modifying the
~/.profile file and exporting the directory as part of the PATH.
Creating a symbolic link allows you to save Chromedriver at a custom location while still being able to access it from a directory that is already in the PATH. It provides flexibility and convenience in managing the Chromedriver executable.