Setting up Phantom.js on Ubuntu

PhantomJS is a headless (no GUI) browser used for testing and capturing screen shots of web sites. I use it to test JavaScript in Ruby on Rails apps, along with Poltergeist, a driver for Capybara, the library for simulating user interaction with a web application.

  1. Go to the PhantomJS download page

  2. Download the Linux binary, it will be something like this phantomjs-1.9.2-linux-x86_64.tar.bz2

  3. un-bzip and untar the archive file.

bunzip2 phantomjs-1.9.2-linux-x86_64.tar.bz2  
tar -xvf phantomjs-1.9.2-linux-x86_64.tar  

4. move the file into the /opt directory

sudo mv phantomjs-1.9.2-linux-x86_64 /opt/phantomjs  
  1. If you don't have a ~/bin directory in your path, now would be a good time to make one and include it in your path.

  2. Link the phantomjs executable to a link in your ~/bin directory.

cd ~/bin  
ln -s /opt/phantomjs/bin/phantomjs phantomjs  
  1. You're done! Test out the phantomjs command with phantomjs --help

Ivan Storck

Web Developer, Teacher, Entrepreneur. Co-founder of Sustainable Websites, Code Fellows, and Aerobatic. Ivan lives in Seattle and enjoys paddling his SUP, spending time with family, and traveling.