How to install PhantomJs on a CentOS server

Uncategorized

I was playing around with using a server to run end to end scenario testing using PhantomJs (new to it, check out some useful books here). I like that PhantomJs has minimal requirements. However, I did have to install a couple of libraries that I didn’t find clear documentation for. So to benefit anyone who might be trying to do this, here are my steps:

Download Phantom

[samh@do ~]$ curl -O https://phantomjs.googlecode.com/files/phantomjs-1.9.1-linux-i686.tar.bz2
 % Total % Received % Xferd Average Speed Time Time Time Current
 Dload Upload Total Spent Left Speed
100 13.0M 100 13.0M 0 0 2908k 0 0:00:04 0:00:04 --:--:-- 3402k

Extract directory

[samh@do ~]$ tar xvf phantomjs-1.9.1-linux-i686.tar.bz2

Copy binary to bin folder (note you may need to use sudo if you are not logged in with root priveleges)

[samh@do ~]$ cp phantomjs-1.9.1-linux-i686/bin/phantomjs /usr/local/bin

You will notice that this is not enough to run Phantom and you will encounter this error:

[samh@do ~]$ phantomjs hello.js
phantomjs: error while loading shared libraries: libfreetype.so.6: cannot open shared object file: No such file or directory

Here is the step to eliminate it:

[samh@do ~]$ sudo yum install freetype

Then you will see another error:

[samh@do ~]$ phantomjs hello.js
phantomjs: error while loading shared libraries: libfontconfig.so.1: cannot open shared object file: No such file or directory

And here’s how to eliminate it:

[samh@do ~]$ sudo yum install fontconfig

This is it. Everything should work now:

[samh@do ~]$ phantomjs hello.js
Hello, world!