user2240134
user2240134

Reputation: 19

Installing Nokogiri on Yosemite using gem

When I try and install Nokogiri with the following command:

gem install nokogiri

I get the following error:

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

    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb
checking if the C compiler accepts ... yes
checking if the C compiler accepts -Wno-error=unused-command-line-argument-hard-error-in-future... no
Building nokogiri using packaged libraries.
-----
The file "/usr/include/iconv.h" is missing in your build environment,
which means you haven't installed Xcode Command Line Tools properly.

To install Command Line Tools, try running `xcode-select --install` on
terminal and follow the instructions.  If it fails, open Xcode.app,
select from the menu "Xcode" - "Open Developer Tool" - "More Developer
Tools" to open the developer site, download the installer for your OS
version and run it.
-----
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
  --with-opt-dir
  --without-opt-dir
  --with-opt-include
  --without-opt-include=${opt-dir}/include
  --with-opt-lib
  --without-opt-lib=${opt-dir}/lib
  --with-make-prog
  --without-make-prog
  --srcdir=.
  --curdir
  --ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
  --help
  --clean
  --use-system-libraries
  --enable-static
  --disable-static
  --with-zlib-dir
  --without-zlib-dir
  --with-zlib-include
  --without-zlib-include=${zlib-dir}/include
  --with-zlib-lib
  --without-zlib-lib=${zlib-dir}/lib
  --enable-cross-build
  --disable-cross-build

I have seen a lot of these errors on the web, and tried all options to fix the problem, but have had no luck. I have tried updating Xcode, have tried gem install nokogiri -- --use-system-libraries, as well as with libxml2/libxslt installations but I am still not able to rectify the problem. I am wondering if anyone out there has had similar problems, and, if so, how did you solve this?

Upvotes: 1

Views: 841

Answers (2)

bgentry
bgentry

Reputation: 316

I ran into this same issue after doing an OS X system restore and moving around some user accounts. Despite running xcode-select --install multiple times, the error persisted.

I was able to resolve it by downloading the install package for the Command Line Tools from Apple's download page.

Upvotes: 2

diabolist
diabolist

Reputation: 4099

You could try using RVM. By giving you a separate Ruby environment it might remove some possibilities that could cause this problem, and it's is quite clever at installing Nokogiri.

It will also tell you if you haven't got the developer tools installed properly.

Upvotes: 0

Related Questions