Yesterday I was setting up a new box with Mac OS X Lion at the office. I had installed homebrew, rvm and ruby 1.9.3rc1 and when I ran bundle in a project folder I got the following error:

Installing net-ssh (2.1.4) 
Installing net-scp (1.0.4) 
Installing nokogiri (1.5.0) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /Users/arvid/.rvm/rubies/ruby-1.9.3-rc1/bin/ruby extconf.rb 
extconf.rb:10: Use RbConfig instead of obsolete and deprecated Config.
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.

I checked out nokogiri’s Mac OS X installation instructions. The instructions didn’t work for the above error and I ended up doing the following instead:

~ $ brew install libiconv
==> Downloading
~ $ brew link libiconv
Linking /usr/local/Cellar/libiconv/1.14... 17 symlinks created

The trick is to do the brew link command, this adds libiconv to the homebrew path so the compiler can find the lib and header files. After running those homebrew commands the nokogiri installation worked:

~ $ gem install nokogiri
Building native extensions.  This could take a while...
Successfully installed nokogiri-1.5.0
1 gem installed