If you are running Selenium or other kind of application testing platform, you may have a need to install the PhantomJS package to make it work properly. Unfortunately, if you are on Ubuntu, this isn’t quite the straightforward install most other apps are.
Prerequisites
- Must be running Ubuntu
- Must be running x86/64-bit
- Must have root / sudo access on the system
Installing PhantomJS
First off, make sure everything else is up to date on your system by running:
sudo apt update && sudo apt upgrade
Next, install a couple of necessary packages:
sudo apt install build-essential chrpath libssl-dev libxft-dev
Now install the basic packages required by PhantomJS to run (these are mainly font definitions so pages render properly):
sudo apt install libfreetype6 libfreetype6-dev libfontconfig1 libfontconfig1-dev
Now we need to get the package from the PhantomJS website:
cd ~
export PHANTOMJS="phantomjs-1.9.8-linux-x86_64"
wget https://bitbucket.org/ariya/phantomjs/downloads/$PHANTOMJS.tar.bz2
sudo tar xvjf $PHANTOMJS.tar.bz2
We are using the variable PHANTOMJS
to store the version that you wish to install. This can be modified to suite any other version that you might wish to install.
After that finishes, we need to move the package to /usr/local/share/
and create a symlink so that we can execute it from our PATH:
sudo mv $PHANTOMJS /usr/local/share
sudo ln -sf /usr/local/share/$PHANTOMJS/bin/phantomjs /usr/local/bin
Testing
Once that has completed, you should be all set to run PhantomJS on your system. You can test this by typing:
phantomjs --version