Build Instructions

Warning: Compiling PhantomJS from source takes a long time, mainly due to thousands of files in the WebKit module. With 4 parallel compile jobs on a modern machine, the entire process takes roughly 30 minutes. It is highly recommended to download and install the ready-made binary package if it is available.

Mac OS X

Install Xcode and the necessary SDK for development (gcc, various tools, libraries, etc).

git clone git://github.com/ariya/phantomjs.git
cd phantomjs
git checkout 1.9
./build.sh

This produces a static build bin/phantomjs. This is a self-contained executable, it can be moved to a different directory or another machine.

Linux

For Ubuntu Linux (tested on a barebone install of Ubuntu 10.04 Lucid Lynx, Ubuntu 11.04 Natty Narwhal, Ubuntu 12.04 Precise Pangolin):

sudo apt-get update
sudo apt-get install build-essential chrpath git-core libssl-dev libfontconfig1-dev
git clone git://github.com/ariya/phantomjs.git
cd phantomjs
git checkout 1.9
./build.sh

For Amazon EC2 AMI (release 2011.09, 2012.03) and CentOS/RHEL 6:

sudo yum install gcc gcc-c++ make git openssl-devel freetype-devel fontconfig-devel
git clone git://github.com/ariya/phantomjs.git
cd phantomjs
git checkout 1.9
./build.sh

Note 1: build.sh by default will launch parallel compile jobs depending on the available CPU cores, e.g. 4 jobs on a modern hyperthreaded dual-core processor. If necessary, e.g. when building on a virtual machine/server or other limited environment, reduce the jobs by passing a number, e.g ./build.sh --jobs 1 to set only one compile job at a time.

Note 2: To create an RPM package (EC2 AMI, CentOS, or RHEL), make sure rpm-build package is installed and then run the following after a successful build:

cd rpm
./mkrpm.sh phantomjs 

Note 3: Compile time for Ubuntu 12.04 running on Amazon EC2 M1 Extra Large (m1.xlarge, 4 cores): 20 minutes, M1 Large (m1.large, 2 cores): 50 minutes, M1 Medium (m1.medium, 1 core): 100 minutes.

Windows

Install Microsoft Visual C++, either version 2010 or 2008 (the Express edition should work just fine).

First step is to build OpenSSL static library. Go to openssl.org/source and download the source package (tested with version 1.0.1). Unpack the package to a working directory, e.g. C:\openssl. Configure and build OpenSSL:

perl Configure VC-WIN32 no-asm --prefix=C:\openssl
ms\do_ms
nmake -f ms\nt.mak install

Get PhantomJS source code:

git clone git://github.com/ariya/phantomjs.git
cd phantomjs
git checkout 1.9

Edit file src\qt\preconfig.cmd and change OPEN_SSL_DIR variable to point to the OpenSSL working directory.

Finally, compile PhantomJS:

cd src\qt
preconfig.cmd
cd ..\..
src\qt\bin\qmake -r
nmake

This produces a static build bin/phantomjs.exe. This is a self-contained executable, it can be moved to a different directory or another machine.