Installing nokogiri / libv8 / therubyracer on OS X


Etienne van Delden – 6 April 2016
239 words in about 1 minute

If you are developing Rails or Ruby applications, you probably have to install nokogiri, libv8 or therubyracer at some point.

Sadly enough, installing one of these gems on Mac OS X is always a hassle, for which I always keep forgetting the solution.

Here is my definite guide to installing nokogiri, libv8, therubyracer!


Before installing the actual gems, we will be using the following:

  • brew; for installing (older) versions of xml2 and v8
  • bundler; for easier gem management

If you are only interested in installing the gem directly, you can use gem install GEM -- --OPTIONS instead of bundle config and bundle install.


Installation of nokogiri depends on xml2, so we’ll install that first.

brew install xml2

Now we can setup bundler to correctly install nokogiri.

bundle config build.nokogiri --use-system-libraries --with-xml2-include=/usr/local/opt/libxml2/include/libxml2
bundle install


Installation of libv8 depends on (wait for it!) v8. OS X comes with a pre-installed v8.

bundle config build.libv8 --with-system-v8
bundle install

Note If you also need therubyracer, then see below


The therubyracer only works with libv8 that depends on an older version of v8, so we need to first install that older version.

brew tap homebrew/versions
brew install v8-315

Now we can setup bundler to correctly install therubyracer and libv8

bundle config build.therubyracer --with-v8-dir=/usr/local/opt/v8-315
bundle config build.libv8 --with-v8-dir=/usr/local/opt/v8-315

bundle install Happy coding!

This post is an amalgamation of three separate posts I wrote on


Etienne van Delden

Hi! I’m Etienne! I’m a developer and Dungeon Master.

At Kabisa, privacy is of the greatest importance. We think it is important that the data our visitors leave behind is handled with care. For example, you will not find tracking cookies from third parties such as Facebook, Hotjar or Hubspot on our website. Only cookies from Google and Vimeo are used in order to improve the user experience of our visitors. These cookies also ensure that relevant advertisements are displayed. Read more about the use of cookies in our privacy statement.