How to Install PhantomJS On CentOS 7

Reading Time: 3 minutes

What is PhantomJS?

In this article, we will be discussing PhantomJS. PhantomJS is, in the simplest of terms, is a headless browser (headless, meaning without a GUI) that utilizes a javascript API. This function makes the browser very useful when used for:

  • Page automation - Accessing web pages and extracting information using the standard DOM API, or with usual libraries like jQuery.

  • Screen capture - Programmatically capturing web content, including SVG and Canvas. Create website screenshots with a thumbnail preview.
  • Headless website testing - Running functional tests with the Jasmine, QUnit, Mocha, and WebDriver frameworks.
  • Network monitoring - Monitoring page load times and exporting that info as standard HAR files. It also automates performance analysis using YSlow and Jenkins.


To ensure PhantomJS installs and operates correctly, we need to verify the following packages are installed and up to date on our system:

  • glibc
  • fontconfig
  • fontconfig-devel
  • freetype
  • freetype-devel
  • wget
  • bzip2

The best way to verify if all required packages are installed is by utilizing the “YUM list installed packages" command. We can check this using the following command:  

[root@host ~]# yum list installed 

This command lists all installed packages in alphabetical order.

Because the installed packages list can be pretty long, using the “more” or “less” commands piped after the list command will allow you to scroll through the list quickly.

[root@host ~]# yum list installed | more
[root@host ~]# yum list installed | less

Additionally, we can grep for specific packages in the prerequisites list:

[root@host ~]# yum list installed | grep "package name" 

If any of the packages are missing, we can use this command to install them (choose some or all of the packages to install):

[root@host ~]# sudo yum install glibc fontconfig freetype freetype-devel fontconfig-devel wget bzip2

Download and Install PhantomJS

PhantomJS does not require installation in the traditional sense. All we have to do is to download the latest release from the official website, then extract the archive to the desired system location.

We need to state clearly that currently, the development of PhantomJS has been suspended until further notice.

Moving forward, we can use wget to download the file:

[root@host ~]# wget

Once the download has completed, we will need to extract the files:

[root@host ~]# tar xvjf phantomjs-2.1.1-linux-x86_64.tar.bz2 -C /usr/local/share/

After the files have been extracted, we will need to create a soft (or “symbolic”) link between the PhantomJS binary file and the systems bin directory.

[root@host ~]# ln -sf /usr/local/share/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin

Verify the PhantomJS Install

First, let’s check the software version. We can accomplish this by typing:

[root@host ~]# phantomjs --version

We can also check the version using the PhantomJS prompt. To open the PhantomJS prompt, type:

[root@host ~]# phantomjs

At the new prompt, type the “phantom.version” command. The output should look like this:

[root@host ~]# phantomjs
phantomjs> phantom.version
	"major": 2,
	"Minor": 1,
	"patch": 1

Test PhantomJS

To ensure that everything is working as intended, we will create a short .js script. Create a new text file that contains the following lines:

console.log('Hello, world!');

Save it as helloworld.js and then run:

[root@host ~]# phantomjs helloworld.js

If everything is working correctly, the output should look like this:

[root@host ~]# phantomjs helloworld.js
Hello, world!

As a side note, the Ubuntu installation is nearly the same except we would use apt-get instead of yum.

Check The Convenient Coupon Below For Awesome Savings!

Utilizing PhantomJS is an excellent software-based method to accomplish multiple tasks on your dedicated server. Leveraging one of our Virtual dedicated servers would be the perfect fit for this use,

Give us a call at 800.580.4985, or open a chat or ticket with us to speak with one of our knowledgeable Solutions or Experienced Hosting advisors to learn how you can take advantage of this software today!

Avatar for Denis Bosack

About the Author: Denis Bosack

Latest Articles

Change cPanel password from WebHost Manager (WHM)

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change the root password in WebHost Manager (WHM)

Read Article