Skip to content

Instantly share code, notes, and snippets.

@joshwand
Created July 10, 2011 03:53
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save joshwand/1074244 to your computer and use it in GitHub Desktop.
How to fix "libiconv is missing" problem installing Nokogiri on 10.6 with MacPorts

When installing Nokogiri on 10.6 with macports, the build fails because libiconv is missing:


Building native extensions.  This could take a while...
ERROR:  Error installing nokogiri:
       ERROR: Failed to build gem native extension.

/Users/jmacdonald/.rvm/rubies/ruby-1.8.7-p174/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.
...

The Nokogiri install page recommends you install libxml2 and libxslt:

$ sudo port install libxml2 libxslt

When I tried to do this, I got the following error:

Error: "You cannot install libxml2 for the architecture(s) x86_64" because Error: "its dependency libiconv only contains the architecture(s) i386."

The trick to fixing this is to rebuild libiconv as universal. However, you can’t just uninstall and reinstall libiconv, since too many packages depend on it. You can build it for x86_64 though, using the following command:

$ sudo port install libiconv +universal

Then you can install libxml2 and libxslt:

$ sudo port install libxml2 libxslt

at which point you can now do
$ sudo gem install nokogiri

To summarize:


$ sudo port install libiconv +universal
$ sudo port install libxml2 libxslt
$ sudo gem install nokogiri

@charliepark
Copy link

I had to run it with

$ sudo port install libxslt +universal

to get it to fully work, but apart from that, this worked perfectly.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment