Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 633
user3591456 Avatar asked May 01 '14 02:05

user3591456


2 Answers

Setting NOKOGIRI_USE_SYSTEM_LIBRARIES=1 before actually installing the gem did the trick for me.

Summarising:

  • If previously installed, uninstall the gem:
    $ gem uninstall nokogiri

  • Use Homebrew to install libxml2, libxslt and libiconv if needed:
    $ brew install libxml2 libxslt libiconv

  • Install the gem specifying the paths to the libraries to be linked against:
    $ NOKOGIRI_USE_SYSTEM_LIBRARIES=1 gem install nokogiri -- --use-system-libraries --with-iconv-dir="$(brew --prefix libiconv)" --with-xml2-config="$(brew --prefix libxml2)/bin/xml2-config" --with-xslt-config="$(brew --prefix libxslt)/bin/xslt-config"

like image 94
Eduardo Avatar answered Oct 09 '22 18:10

Eduardo


  • As a self-contained solution, I've put together this ruby script as a gist that should work with any recent Mac OS X / Homebrew installation.
  • You're basically just on on relying Homebrew's libraries instead of the outdated Apple ones. Simple.
  • You can configure and install with Bundler (instead of gem) by passing bundle as an argument.

Check it out, and please feel free to contribute--maybe we can boil this down to one script to fix them all!

like image 26
Steve Benner Avatar answered Oct 09 '22 16:10

Steve Benner