A quick search reveals that I’m not the only one who’s had difficulty installing the nokogiri Ruby gem on Mac OS X. The official docs recommend installing the fink or macports versions of libxml2, and so does this nokogiri tutorial over on the Engine Yard blog. I like macports. It’s a good way to stay up to date with the latest and greatest versions of everything, but I have this thing about trying to make things work with the libraries that come as standard on Mac OS X. I don’t know, maybe it’s that it reduces dependencies, or maybe I’m just strange.
Anyway, here’s how I got nokogiri to install under Snow Leopard without resorting to macports or fink:
sudo gem install nokogiri -- --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib --with-xslt-dir=/usr
What’s weird is that, unless I’m mistaken, those paths are exactly where nokogiri should be looking for the relevant libxml2 files in the first place! I’m still to find out whether it all works as it’s supposed to. But installation is the first step! Let me know if it works for you.


Installing nokogiri on Mac OS X: http://rickyrobinson.id.au/2010/01/25/in... (RickyRobinson.id.au)
@rickyrobinson is nokogiri the best rails xml parser?
@simultech Apparently it’s got a few things going for it. I had to install it because of the cucumber -> webrat -> nokogiri dependencies.
Ricky,
You rock! Was TEARING my hair out trying to get this thing to install! This was the only thing that worked!
Used this method today, nearly two years after the post (having first tried installing and linking libxml2 and libxslt with Homebrew), and it is *still* the way that worked – unlike the official docs at http://nokogiri.org/tutorials/installing_nokogiri.html. Thanks!
I was having major problems with getting nokogiri to install on Lion as part of a bundle and fixed it using CFLAGS=”-I/usr/local/include -L/usr/local/lib” bundle install.