109
votes

I upgraded my OSX (Lion) to Mavericks and I can't install Nokogiri for my projects.

I already install XCode 5.0.1, Command Line Tools (using xcode-select --install), and already installed libxml2 from Homebrew and I am still having problems.

The error is:

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

/Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/bin/ruby extconf.rb
checking for libxml/parser.h... *** 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
    --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=/Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/bin/ruby
    --with-zlib-dir
    --without-zlib-dir
    --with-zlib-include
    --without-zlib-include=${zlib-dir}/include
    --with-zlib-lib
    --without-zlib-lib=${zlib-dir}/lib
    --with-iconv-dir
    --without-iconv-dir
    --with-iconv-include
    --without-iconv-include=${iconv-dir}/include
    --with-iconv-lib
    --without-iconv-lib=${iconv-dir}/lib
    --with-xml2-dir
    --without-xml2-dir
    --with-xml2-include
    --without-xml2-include=${xml2-dir}/include
    --with-xml2-lib
    --without-xml2-lib=${xml2-dir}/lib
    --with-xslt-dir
    --without-xslt-dir
    --with-xslt-include
    --without-xslt-include=${xslt-dir}/include
    --with-xslt-lib
    --without-xslt-lib=${xslt-dir}/lib
    --with-libxslt-config
    --without-libxslt-config
    --with-pkg-config
    --without-pkg-config
    --with-libxml-2.0-config
    --without-libxml-2.0-config
    --with-libiconv-config
    --without-libiconv-config
/Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:368:in `try_do': The complier failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:452:in `try_cpp'
    from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:853:in `block in find_header'
    from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:693:in `block in checking_for'
    from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:280:in `block (2 levels) in postpone'
    from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:280:in `block in postpone'
    from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:276:in `postpone'
    from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:692:in `checking_for'
    from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:852:in `find_header'
    from extconf.rb:116:in `<main>'


Gem files will remain installed in /Users/ericcamalionte/Locaweb/code/dns-panel/vendor/bundle/ruby/1.9.1/gems/nokogiri-1.5.9 for inspection.
Results logged to /Users/ericcamalionte/Locaweb/code/dns-panel/vendor/bundle/ruby/1.9.1/gems/nokogiri-1.5.9/ext/nokogiri/gem_make.out
An error occured while installing nokogiri (1.5.9), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.5.9'` succeeds before bundling.

I installed libxml2, libxslt and libiconv from Homebrew, and set the params to install Nokogiri, but don't work too.

I can't find what's wrong in my enviroment, can you help me?

30
Try opening xcode and accept the EULA/license.moander

30 Answers

244
votes

You can also install Nokogiri on Mac OS X 10.9 Mavericks with full XCode Install using:

gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2

Update

For those using Yosemite the following command will work:

gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/libxml2 --use-system-libraries

or, it might actually be in your MacOSX10.11.sdk folder (mine was as of 18-Sep-2015) anyways, so even if you are not yet fully up to El Capitan, I had recently updated XCode and you may need to use the El Capitan SDK path, which follows next:

Update

For those using El Capitan the following command will work:

gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2 --use-system-libraries

Update

For those using Sierra the following command will work:

gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/libxml2 --use-system-libraries
30
votes

After navigating the animated GIFs here, all that I had to do was simply xcode-select --install and the gem install nokogiri worked fine.

20
votes

I found this log and saw that gcc-4.2 was not found:

package configuration for libxslt
cflags: -I/usr/local/Cellar/libxslt/1.1.28/include -I/usr/local/Cellar/libxml2/2.9.1/include/libxml2
ldflags: -L/usr/local/Cellar/libxslt/1.1.28/lib -L/usr/local/Cellar/libxml2/2.9.1/lib
libs: -lxslt -lxml2 -lz -lpthread -liconv -lm -lxml2

package configuration for libxml-2.0
cflags: -I/usr/local/Cellar/libxml2/2.9.1/include/libxml2
ldflags: -L/usr/local/Cellar/libxml2/2.9.1/lib
libs: -lxml2

package configuration for libiconv is not found
"/usr/bin/gcc-4.2 -o conftest -I/Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/include/ruby-1.9.1/x86_64-darwin11.4.0 -I/Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/include/ruby-1.9.1/ruby/backward -I/Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/include/ruby-1.9.1 -I. -I/usr/local/Cellar/libxslt/1.1.28/include -I/usr/local/Cellar/libxml2/2.9.1/include/libxml2 -I/usr/local/Cellar/libiconv/1.14/include -I/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320@dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxml2/2.8.0/include -I/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320@dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxslt/1.1.26/include -I/Users/ericcamalionte/.rvm/usr/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE    -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wshorten-64-to-32 -Wno-long-long  -fno-common -pipe  -g -DXP_UNIX -O3 -Wall -Wcast-qual -Wwrite-strings -Wconversion -Wmissing-noreturn -Winline -DNOKOGIRI_USE_PACKAGED_LIBRARIES -DNOKOGIRI_LIBXML2_PATH='"/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320@dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxml2/2.8.0"' -DNOKOGIRI_LIBXSLT_PATH='"/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320@dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxslt/1.1.26"' -I/usr/local/Cellar/libxslt/1.1.28/include -I/usr/local/Cellar/libxml2/2.9.1/include/libxml2  -I/usr/local/Cellar/libxml2/2.9.1/include/libxml2  conftest.c  -L. -L/Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib -L/usr/local/Cellar/libxslt/1.1.28/lib -L/usr/local/Cellar/libxml2/2.9.1/lib -L/usr/local/Cellar/libiconv/1.14/lib -L/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320@dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxml2/2.8.0/lib -L/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320@dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxslt/1.1.26/lib -L/Users/ericcamalionte/.rvm/usr/lib -L.  -Wl,-rpath,/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320@dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxml2/2.8.0/lib -Wl,-rpath,/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320@dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxslt/1.1.26/lib -L/usr/local/Cellar/libxslt/1.1.28/lib -L/usr/local/Cellar/libxml2/2.9.1/lib -L/usr/local/Cellar/libxml2/2.9.1/lib     -lxslt -lxml2 -lz -lpthread -liconv -lm -lxml2  -lxml2  -lruby.1.9.1-static  -lpthread -ldl -lobjc  "
sh: /usr/bin/gcc-4.2: No such file or directory
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main() {return 0;}
/* end */

To solve this problem I intalled apple-gcc42 using homebrew brew install apple-gcc42 and created a symlink to my /usr/bin :

sudo ln -s /usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/gcc-4.2 /usr/bin/gcc-4.2

15
votes

If you're running Xcode 5.1, the command line tools don't work for nokogiri 1.6.1. You'll need to download the Late october 2013 tools from Apple. Once you do that run

sudo xcode-select -s /Library/Developer/CommandLineTools/

to set up your machine to use the Xcode 5.0.X command line tools, then run

gem install nokogiri

If you want to reset your command line tools to the Xcode.app version afterward run

sudo xcode-select -r

Or, another thing you can do is add the flag to ignore unknown command line arguments. Then the install looks like this:

sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future gem install nokogiri
12
votes

This is what worked for me on OSX Mavericks:

sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future gem install nokogiri -v '1.6.1' --verbose --no-ri --no-rdoc
10
votes

I'm on OSX Mavericks and my problem turned out to be a bad install of Ruby.

So, I reinstalled ruby with rvm :

rvm remove ruby 2.0.0p451
rvm remove ruby-2.0.0-p451 && rvm install ruby-2.0.0-p451

I was then able to

gem install nokogiri --no-ri --no-rdoc

Problem solved.

9
votes

I like to stick with system-provided stuff typically. This worked for me:

gem install nokogiri -- --with-iconv-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/ --with-iconv-lib=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib/
5
votes

I ran into this problem immediately after installing the Mavericks 10.9.5 update and the 10.9 Developer tools update from Apple. I ran xcode-select --install, but that did not fix the problem. Then I opened XCode, accepted the eula, and quit XCode. That fixed the problem.

3
votes

I had this problem today, on Maverick, this is how I ended up solving the issue:

brew update
brew install libiconv
brew link libiconv

Make sure that you know the version of libiconv in Cellar mine below was 1.14, then install as below:

gem install nokogiri -- --with-iconv-dir=/usr/local/Cellar/libiconv/1.14

If you require a particular version of nokogiri e.g -v '1.6.2.1' then install as:

gem install nokogiri -v '1.6.2.1' -- --with-iconv-dir=/usr/local/Cellar/libiconv/1.14

Nokogiri was installed successfully!

3
votes

This is the same as @thomas_witt's post but works on Mac OS X Sierra:

gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/libxml2 --use-system-libraries
2
votes

To get the install to work, I had to modify the filepaths in the gem install command to match those on my system. I have different versions of libxml2 and libiconv and a slightly different file structure. The command, with my modifications, is:

gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.9.1/include/libxml2 
                        --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.1/lib 
                        --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.28 
                        --with-iconv-include=/usr/local/Cellar/libiconv/1.13.1/include 
                        --with-iconv-lib=/usr/local/Cellar/libiconv/1.13.1/lib
2
votes

For people using MacPorts, make sure you have installed libxml2 via MacPorts. Then type:

bundle config build.nokogiri --use-system-libraries
bundle install

This should do the trick, worked for me without using full paths.

2
votes

Use brew install libxml2 libxslt if you use Homebrew.

2
votes

Here is another reference:

system: OS X Yosemite 10.10
rvm: 1.26.10
brew: 0.9.5
ruby: ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]

I got error while installing nokogiri

error like this:

.rvm/rubies/ruby-2.2.0-p0/lib/ruby/1.9.1/mkmf.rb:368:in `try_do': The complier failed to generate an executable file. (RuntimeError)

You have to install development tools first.

then probably need:

$ xcode-select --install

or if you got error like

checking for libxml/parser.h... no

I just fix the lib path by:

gem uninstall nokogiri libxml-ruby
brew update
brew uninstall libxml2
brew install libxml2 libxslt
gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.9.2/include/libxml2/libxml --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.2/lib --with-iconv-dir=/usr/local/Cellar/libiconv/1.14/ --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26/

for bundle need something like:

bundle config build.nokogiri --with-xml2-include=/usr/local/Cellar/libxml2/2.9.2/include/libxml2/libxml --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.2/lib --with-iconv-dir=/usr/local/Cellar/libiconv/1.14/ --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26/
bundle install
2
votes

This works for me

system: OS X Yosemite 10.10
rvm: 1.26.10
ruby: ruby 2.2.1 

Just run below two commands

$ xcode-select --install

It will ask you to download say "yes" then it will ask to install the xcode component click install.

Now try to install gem with below command

gem install nokogiri --no-ri --no-rdoc

This works for me with above environment.

1
votes

I ran into the same issue for Mavrick, and the solution was:

xcode-select --install

However, that is not working as Apple's download page for Command-line-tool does not have that installer available publically now.

So, if you want to have the command-line tools for Mavricks you need to have a paid account. Then only you will be able to install it. Once you install it you will not face this issue with Nokogiri.

1
votes

I had this same error on a fresh Mavericks install. After having a lapse of judgement I renamed my Xcode app bundle to Xcode 5.0.1.app.

Apparently the Nokogiri installation script does not quote its paths and so the space in the file name caused all sorts or troubles. It wasn't until I tried brew install libxml2 that the error became obvious.

Lesson learned: spaces in file names are evil.

1
votes

In my case, I had to actually run /usr/bin/gcc-4.2 after symlinking it. You have to accept the license agreement, otherwise it hangs.

1
votes

The error message gives a clue here: The compiler failed to generate an executable file. (RuntimeError)

xcode-select --install # not sure if this is required  
brew install apple-gcc42  
gem install nokogiri  

You also might need to brew install and link these:

libxml2 libxslt
1
votes
brew install libxml2 libxslt
gem install nokogiri -- \
    --with-xml2-include=/usr/local/Cellar/libxml2/*/include/libxml2 \
    --with-xml2-lib=/usr/local/Cellar/libxml2/*/lib \
    --with-xslt-dir=/usr/local/Cellar/libxslt/*
1
votes

For me the error was that that gcc (4.2.1, installed from Homebrew) was complaining that:

-E, -S, -save-temps and -M options are not allowed with multiple -arch flags

I solved the issue by forcing x86_64 only:

ARCHFLAGS="-arch x86_64" gem install nokogiri 
1
votes

After upgrading to Maverick, I had a similar problem. I use RVM with Ruby 1.9.2-p320, and I tried several solutions given here, but nothing solved the problem.

Then I changed to Ruby 2.1.2, and bundle install installed Nokogiri immediately.

1
votes

If anyone is having this issue on el capitan, whilst using bundler.

Make sure the xcode command line tools are installed and run this:

bundle config build.nokogiri --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2 --use-system-libraries
1
votes

I was facing the same issue from past two weeks while trying to run a rails 3 version application.

The issue is that your rvm/rbenv is not using the C compiler.

Use this command for rvm to take compatible C compiler

CC=gcc rvm install-version

So if you are using Ruby 1.9.3, use it this way

CC=gcc rvm install-1.9.3

Use this command every time you are not able to bundle install or anything. This thing is working on El Capitan, rails 3.2.16, ruby 1.9.3, mysql 5.7 Hopefully, It will resolve the issue.

I was facing the same issue from past two weeks while trying to run a rails 3 version application.

The issue is that your rvm/rbenv is not using the C compiler.

Use this command for rvm to take compatible C compiler

CC=gcc rvm install-version

So if you are using Ruby 1.9.3, use it this way

CC=gcc rvm install-1.9.3

Use this command every time you are not able to bundle install or anything.

This thing is working on El Capitan, rails 3.2.16, ruby 1.9.3, mysql 5.7 Hopefully, It will resolve the issue. And also if you already have the Xcode and then also you are not getting the same errors installing any gem, try this solution.

1
votes

I added my findings here after I came across this same issue shortly after an Upgrade: http://jasdeep.ca/2013/10/installing-nokogiri-fails-os-x-mavericks/

The fix simply is these 2 commands:

xcode-select --install
gem install nokogiri

Hope it helps.

0
votes

I had this issue as well. Running brew doctor showed that I had an unexpected version of libiconv in /user/local/lib.

Warning: Unbrewed dylibs were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected dylibs:
    /usr/local/lib/libcharset.1.dylib
    /usr/local/lib/libiconv.2.dylib

So I removed them, and rebrewed libxml:

rm  /usr/local/lib/libiconv*
andromeda:nokogiri-1.6.0 Jeff$ brew install libxml2 libxslt
...
==> Summary
🍺  /usr/local/Cellar/libxslt/1.1.28: 145 files, 3.3M, built in 36 seconds

Finally, I installed nokogiri:

Jeff$ gem install nokogiri
Building native extensions.  This could take a while...
Successfully installed nokogiri-1.6.0
1 gem installed
0
votes

None of these answers worked for my particular case, and since I am a newb I figured my solution might be able to help someone else.

I am using Yosemite and was using Ruby 1.9.3p547. There was a security exposure for p547 so I was trying to update to Ruby 1.9.3p550 or higher. I used RVM, then tried to migrate my gems and many of them didn't go. Then I tried to bundle install but that was failing and I thought maybe it was a conflict between the various paths and dependencies so I removed the older version of Ruby. This broke everything.

I kept getting a message saying that the C compiler was missing, even though I had downloaded XCode and recently updated the CLI tools. I found another website that told me to download a third party GCC, which I did. which made everything worse.

Now I'm getting a message saying I need to fix my profiles and PATHs or it might just be easier to reinstall OSX. So I did.

Anyway, longer story merely long: the solution that finally worked for me was to get rid of RVM and just use brew to download the Ruby version I wanted then before running bundle install. Install the correct version of Nokogiri FIRST.

brew install ruby193
sudo gem install nokogiri -v '1.6.0'
bundle install
0
votes

for windows you can also try local installation:

  1. download the appropriate gem based on your environment.

  2. go to the directory where you saved the gem file.

  3. gem install --local nokogiri-1.6.3.1-x86-mingw32.gem

if not worked you may check if you have zlib and mingw or proper c compiler installed.

0
votes

Every single darn thing on here didn't do it for me (I didn't get into brew reinstalls, oy), but this finally did (found via a bug report on some unrelated project):

gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/usr/include/libxml2

Good luck. Yay for #yakshaving!

-3
votes

Check your Commandline tools version. Set up your machine to use the Xcode 5.0.X command line tools, then run:

gem install nokogiri