Compiling PhantomJS 2.0 on Raspberry Pi

Reason Why

PhantomJS is a tool we use here at work for various front end testing with CasperJS in front of it. Wouldn’t it be cool if we could offload the test scripts to run on the Raspberry Pi? For that we would need the PhantomJS binary for Raspberry Pi.


I’ve seen a couple of pre-built binaries available online here:

I’ve used them both, but development for PhantomJS has run rampart in the past couple of months. These binaries are already outdated. Including some rather annoying bugs using PhantomJS 1.9.8 alongside CasperJS.

So let’s build our own!

First we need to increase our swapfile. The first time I ran the build process I received an “virtual memory exhausted: Cannot allocate memory” error. Go see my post on how to increase the swapfile by visiting:

Second, we need to grab all the dependencies. We are running the Raspbian distribution. So these commands will be specifically tailored to that OS. I grabbed most of the build steps from the official PhantomJS website directly: Build PhantomJS.

sudo apt-get install g++ flex bison-doc bison gperf ruby ruby-dev perl libsqlite3-doc sqlite3-dev libfontconfig1-dev icu-doc libicu-dev libfreetype6 libssl-dev libpng12-dev libjpeg8-dev ttf-mscorefonts-installer fontconfig build-essential chrpath git-core openssl

Now you should be able to download the source.

git clone git://
cd phantomjs
git checkout 2.0

Now you have the entire PhantomJS 2.0 source code downloaded. Now we need to run the build process. On the PhantomJS build page they said this could take a while on even a quad core computer. Well the Raspberry Pi only has access to a single core. So this build will take days! When you’re ready start the build process:


Now grab some coffee and lunch and sleep on it. This will be a while. And by a while it will take approximately two days!

Don’t have two days to waste?

Don’t fuss, I put the binary up here: