Rails tip of the day: Rails + OS X Lion + rvm + nokogiri

I followed this guide, but still had trouble getting nokogiri to install.

Nokogiri complained about libiconv, but the culprit wasn't libiconv. It was libxml2 and libxlst.

Here's the output from trying to install nokogiri:
✗ gem install nokogiri -v 1.4.4
Fetching: nokogiri-1.4.4.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing nokogiri:
	ERROR: Failed to build gem native extension.

/Users/lars/.rvm/rubies/ree-1.8.7-2011.03/bin/ruby extconf.rb 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 http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies. -----


In other instances, I did manage to get it installed somehow, but when I tried to run "rails c", I'd get this error:

/Users/lars/.rvm/gems/ree-1.8.7-2011.03/gems/nokogiri-1.4.4/lib/nokogiri/nokogiri.bundle: [BUG] Segmentation fault


Ultimately, the answer was this gist, which I resisted for a long time, because I thought it wasn't libxml2/libxslt that was missing, but libiconv. I was wrong.

I did have to change the last line to refer to version 2.7.8 of libxml2 rather than 2.7.7. Minor change.

I hope this blog post will save you the hour or two that I wasted wrestling with this stupid issue :)

Boundaries

5 comments

Justin Sunseri
 

tried the gist with the updated 2.7.8 without any luck. I get the same exact error message
Read more
Read less
  Cancel
muttsnutts
 

@Justin That GIST worked fine me on Lion... Out of curiosity, what's your output for each of the following? file /usr/local/Cellar/libxml2/2.7.8/lib/libxml2.2.dylib file /usr/local/Cellar/libxslt/1.1.26/lib/libxslt.1.dylib echo $CC ls -l /usr/bin/gcc*
Read more
Read less
  Cancel
zetarun
 

Hi all, I'm having the same configuration of Justing and still having the same problem also after running the installation command as in the gist. Following is the output of the commands requested: /usr/local/Cellar/libxml2/2.7.8/lib/libxml2.2.dylib: Mach-O 64-bit dynamically linked shared library x86_64 /usr/local/Cellar/libxslt/1.1.26/lib/libxslt.1.dylib: Mach-O 64-bit dynamically linked shared library x86_64 /usr/bin/gcc-4.2 lrwxr-xr-x 1 root wheel 12 29 Ago 23:49 /usr/bin/gcc -> llvm-gcc-4.2 -rwxr-xr-x 1 root wheel 113024 16 Mag 06:37 /usr/bin/gcc-4.2 Thx for the help!
Read more
Read less
  Cancel
zetarun
 

An update: trying the installation with the following command gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.7.8/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.8/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26 --with-iconv-dir=/usr/local/Cellar/libiconv/1.14 I have a new installation error as in this gist: https://gist.github.com/f83c089054be97e05cad
Read more
Read less
  Cancel
Andres Ramirez
 

I finally made it work in my Lion installation with: sudo gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.7.8/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.8/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26 --with-iconv-dir=/usr/local/Cellar/libiconv/1.13.1 Thanks for the help!
Read more
Read less
  Cancel

Leave a comment