Foggy CarrierWave Nokogiri woes on Mac OS X Snow Leopard

I’m developing a Ruby on Rails app on my Mac running Snow Leopard. Tonight I wanted to use the fog gem with CarrierWave to upload files to Amazon S3.

Fog is a Ruby wrapper around different cloud services and CarrierWave provides a very nice API for handling file uploads in Rails apps.

Fog has a dependency on the Nokogiri HTML/XML parsing library, which has a dependency on libxml2, libxslt, and libiconv.

Welcome to pain and suffering…

The versions of libxml2 and libxslt on MacOS X are a little out of date. And when trying to install the nokogiri gem with:

sudo gem install nokogiri

You will get an error like this:

ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
checking for libxml/parser.h... yes
checking for libxslt/xslt.h... yes
checking for libexslt/exslt.h... yes
checking for iconv_open() in iconv.h... no
checking for iconv_open() in -liconv... no
libiconv is missing.
please visit
for help with installing dependencies.

Now, libiconv isn’t missing. It is installed with MacOS X. But nokogiri’s build script can’t find it for some reason.

The Nokogiri install instructions suggest installing newer versions of libxml2 and libxslt to solve this problem. They even kindly provide instructions for a number of operating systems including MacOS X.

Unfortunately none of them worked for me.

I’m using homebrew to manage my additional source packages on my Mac. Installing libxml2 via homebrew is easy:

brew install libxml2

Installing libxslt, not so much.

There is no brew formula for libxslt in the default homebrew git repo. I have no idea why. Perhaps something to do with homebrew’s policy not to dupe stuff bundled with MacOS X. Not sure why they provide a libxml2 forumla then as it comes with MacOS X too.

So to install libxslt I did the following:

curl -o libxslt-1.1.26.tar.gz
tar zxfv libxslt-1.1.26.tar.gz
cd libxslt-1.1.26
./configure \
--prefix=/usr/local/Cellar/libxslt/1.1.26 \
make install
cd .. && rm -rf libxslt-1.1.26 && rm -f libxslt-1.1.26.tar.gz

To install nokogiri I then used the following command line.

sudo gem install nokogiri -- \
--with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26 \
--with-xml2-include=/usr/local/Cellar/libxml2/2.7.7/include/libxml2 \
--with-xml2-lib=/usr/local/Cellar/libxml2/2.7.7/lib \

Now everything seems to be working ok.

2 thoughts on “Foggy CarrierWave Nokogiri woes on Mac OS X Snow Leopard

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s