Build
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 2.0
./build.sh --qt-config "-I /usr/local/include/ -L /usr/local/lib/"
This produces a statically built bin/phantomjs. This is a self-contained executable, it can be moved to a different directory or another machine.
Linux
First, install the development packages of the following tools and libraries: GNU C++ compiler, bison, flex, gperf, Perl, Ruby, SQLite, FreeType, FontConfig, OpenSSL, and ICU. The actual package names may vary from one distribution to another.
On Debian-based distro (tested on Ubuntu 14.04 and Debian 7.0), run:
sudo apt-get install build-essential g++ flex bison gperf ruby perl \
libsqlite3-dev libfontconfig1-dev libicu-dev libfreetype6 libssl-dev \
libpng-dev libjpeg-dev python libx11-dev libxext-dev
Note: It is recommend also to install ttf-mscorefonts-installer package.
On Fedora-based distro (tested on CentOS 6), run:
sudo yum -y install gcc gcc-c++ make flex bison gperf ruby \
openssl-devel freetype-devel fontconfig-devel libicu-devel sqlite-devel \
libpng-devel libjpeg-devel
Then, launch the build:
git clone git://github.com/ariya/phantomjs.git
cd phantomjs
git checkout 2.0
./build.sh
Note: 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.
This produces a build bin/phantomjs. This is an executable; it can be moved to a different directory (e.g. /usr/local/bin) or another machine.
Windows
Note: Supported toolchains: MSVC2012 and MSVC2013.
Note: You must have Perl, Python, Ruby, and Git on PATH. Also, note that Git comes with it's own version of perl.exe. If you have both Git and a separate perl installation in your PATH, please make sure that you separate perl install bin folder comes before the git bin folder in your PATH variable.
Use Visual Studio Command Prompt, run in the top directory. The results will go into bin:
git clone git://github.com/ariya/phantomjs.git
cd phantomjs
git checkout 2.0
build.cmd
Note: git.exe has to be on PATH. If you are using a wrapper (git.cmd, git.bat, etc.) modify build.cmd and replace git.exe with whatever you have on the PATH.
Note: Enabling incremental linking will make the linkage process faster.
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.