Nokogiri gem fails to install in OS X Mavericks Install fails showing:

checking for iconv_open() in iconv.h... no
checking for iconv_open() in -liconv... no
checking for iconv_open() in -liconv... no
checking for libiconv_open() in iconv.h... no
checking for libiconv_open() in -liconv... no
checking for libiconv_open() in -liconv... no
libiconv is missing.


However, looking at nokogiri's mkmf.log, the following errors are shown:

ld: warning: ignoring file /usr/local/Cellar/libxslt/1.1.28/lib/libxslt.dylib, **file was built for x86_64 which is not the architecture being linked (i386)**: /usr/local/Cellar/libxslt/1.1.28/lib/libxslt.dylib

ld: warning: ignoring file /usr/local/Cellar/libxml2/2.9.1/lib/libxml2.dylib, **file was built for x86_64 which is not the architecture being linked (i386)**: /usr/local/Cellar/libxml2/2.9.1/lib/libxml2.dylib

ld: warning: ignoring file /usr/local/Cellar/libiconv/1.14/lib/libiconv.dylib, **file was built for x86_64 which is not the architecture being linked (i386)**: /usr/local/Cellar/libiconv/1.14/lib/libiconv.dylib


I have xcode and it's command tools installed.
My ~/.bash_profile has 64bit compiling forced by: export ARCHFLAGS="-arch x86_64"

I have libxml2, libxslt, and libiconv installed via Homebrew, and each is linked.
I've tried installing all of these without the ARCHFLAG in .bash_profile.

I've also brew install apple-gcc42 and linked, as per how tos I've found.

I've tried installing nokogiri by passing paths to libxml2, libxslt, and libiconv in /usr/local/Cellar/, but the install still fails, with same errors as above.

I've wasted at least a day on this - just trying to get one Ruby gem installed. I'd really like to get back to actually developing.

Can anyone please help?
You can't assume that the version of ruby built-into OS X is compatible with any gems you want to use. Do not try to remove the version of ruby that ships with OS X or update or upgrade it unless with App Store/Software Update/softwareupdate. Most rubiers will tell you don't even bother useing the ruby that ships with OS X. But you can install multiple versions of ruby, and you'll definately need a ruby version manager if you intend to use lots of gems. 

ruby was once quite easy to use, but now, the number of versions that necessarily need to be supported are legion, and gem developers sometimes force you to install a new version of ruby at some other version when you already have a perfectly good ruby installation! Grr. ruby is really starting to chafe, because while the support information might be out there, it is looking more and more like a fishing reel that has birdnested. IMO, ruby is broken, someone's going to have to pull it out and get it neatly reeled in for it to be fixed, and I'm just not up to it. I'm not the guy. Not me.

brewinistas enthusiasm notwithstanding, the homebrew package manager has growing pains typical of an immature package management solution. I use MacPorts to manage... all my installations, but also the various versions of ruby installations that are necessary to use the gems I want. MacPorts requires an appropriate version of xcode; xcode_5.1.1.dmg is the most recent version for Mavericks. rvm uses MacPorts by default if it is installed. 

It appears from your provided logs that you're missing stuff. That's what's nice about MacPorts (and any mature package manager); it takes care of the dependecies for you if they're not installed.

Install MacPorts

 curl -Ok https://distfiles.macports.org/MacPorts/MacPorts-2.2.1.tar.bz2

 tar xf MacPorts-2.2.1.tar.bz2

 cd MacPorts-2.2.1

 ./configure

 make

 sudo make install

 cd ..

 rm -rf Macports-*

 sudo /opt/local/bin/port -v selfupdate


add MacPorts to your $PATH:

 export PATH=/opt/local/bin:/opt/local/sbin:$PATH


take a look at what MacPorts has for ruby

 port search ruby |less


and/or just install nokogiri

 sudo port -vsk install ruby19 libxml2 libxslt 

 sudo gem install nokogiri

 port -vfp clean ruby19 libxml2 libxslt


if there's trouble try

 sudo port upgrade outdated


MacPorts won't affect OS X version of anything, nor homebrew (except to make it superfluous) and keeps everything it installs in /opt making deinstallation a breeze (but this has nothing to do with where ruby keeps its gems, ~/.gem ). But you should really get to know and love MacPorts, it is your friend.

to completely uninstall MacPorts

 sudo port -dfp uninstall --follow-dependencies installed

 sudo port -dfp uninstall all

 sudo rm -rf /opt/local  

 sudo rm -rf /Library/Tcl/macports*