Build PhantomJS from Source

Unless it is absolutely necessary to build PhantomJS from source, it is highly recommended to download and install the ready-made binary package instead.

Requirements

Hardware requirements

RAM: at least 4 GB

Disk space: at least 3 GB

CPU: 1.8 GHz, 4 cores or more

PhantomJS is still a web browser, albeit headless. Thus, building it from source takes a long time (mainly due to thousands of files in the WebKit module). Estimated build time for a 4-core system is 30 minutes.

Linux requirements

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.

Windows requirements

Supported toolchains: MSVC2012 and MSVC2013.

You must have Perl, Python, Ruby, and Git on PATH. Also, note that Git comes with its 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’s bin folder comes before the git’s bin folder in your PATH.

Please also add the folder <phantomjs_path>\src\qt\3rdparty\gnuwin32\bin to your PATH, as required tools such as bison, flex, and gperf will not be found otherwise.
Example:

SET PATH=%CD%\src\qt\3rdparty\gnuwin32\bin;%PATH%

Run the build script from Visual Studio Command Prompt.

Tip: Enabling incremental linking will make the linkage process faster.

OS X requirements

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