How to install PhantomJS on CentOs

  1. Install the required dependencies for PhantomJS:

sudo yum install freetype freetype-devel fontconfig
  1. Download the PhantomJS binary for Linux from the official website: http://phantomjs.org/download.html (or in this case PhantomJS 2.1.1 version)

  2. Extract the downloaded tar file:

tar xvjf phantomjs-2.1.1-linux-x86_64.tar.bz2
  1. Move the extracted folder to /usr/local/share:

sudo mv phantomjs-2.1.1-linux-x86_64/ /usr/local/share/
  1. Create a symlink of the PhantomJS executable to /usr/local/bin:

sudo ln -s /usr/local/share/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin/
  1. Verify the installation by running:

phantomjs --version

It should display the version of PhantomJS that you have installed (2.1.1).

Note:

sudo yum install ttf-mscorefonts-installer

And if you are installing PhantomJS for web scraping, you may need to install additional libraries such as beautifulsoup4 and requests.

You can install them via pip

pip install beautifulsoup4 
pip install requests