Error to install Nokogiri on OSX 10.9 Maverick?

53,404

Solution 1

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

Solution 2

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

Solution 3

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

Solution 4

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

Solution 5

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
Share:
53,404

Related videos on Youtube

squiter
Author by

squiter

Ruby developer.

Updated on March 12, 2020

Comments

  • squiter
    squiter about 4 years

    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?

  • David Portabella
    David Portabella over 10 years
    this didn't solve the issue for me, i still have the same error message :(
  • David Portabella
    David Portabella over 10 years
    I completely uninstalled rvm and ruby (from brew), installed again, and it worked.
  • trojanfoe
    trojanfoe over 10 years
    Does it not compile using clang?
  • trojanfoe
    trojanfoe over 10 years
    How did you compile apple-gcc42 then? It must be easier to use the "default" compiler than to install a new (old) one?
  • squiter
    squiter over 10 years
    So, I just run brew install apple-gcc42.. and just works. That command don't work for you?
  • Quickredfox
    Quickredfox over 10 years
    I ran xcode-select --install before the brew install and all works now.
  • darkmoves
    darkmoves over 10 years
    I had to be very meticulous with the filepaths. It took me multiple tries to correctly construct the commands.
  • squiter
    squiter over 10 years
    I don't have a paid account and I was installed the command-line tools. I installed using terminal, but a friend of mine installed using that download page, and he doesn't have a paid account too.
  • shinesecret
    shinesecret over 10 years
    I Agree with you. Same thing happened with me till 24th Nov, 2013. However if you go to that page now and try to access it, it will give you this error. Weird thing is you login with your credentials but it will keep you login as guest. This is the message I get on page with my account: Apple Developer Program Big Warning We are unable to process your request. Please go back to the previous page, or quit your browser and try your request again. If you require assistance, please contact Apple Developer Support.
  • Justin
    Justin over 10 years
    Please post the stuff here - links are liable to be broken (see the guidelines)
  • darkmoves
    darkmoves over 10 years
    Here's a link to another solution to the issue of an incorrect libxml version.
  • Lucy Bain
    Lucy Bain about 10 years
    @BrunnoDosSantos where did you find the log? I checked my gems/nokogiri-1.6.1/ext/nokogiri/gem_make.out but it just had the same error message as in your question.
  • squiter
    squiter about 10 years
    @LucyBain I realy don't remember.... but I think that log file was in same directory as gem_meake.out...
  • Tim Stephenson
    Tim Stephenson about 10 years
    When I ran brew install apple-gcc42 I gat a warning that it was already installed. Running brew uninstall apple-gcc42 and then installing it did the trick for me.
  • Pop-A-Stash
    Pop-A-Stash about 10 years
    Not for me: "libxml2 is missing. please visit nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies." Still getting same error.
  • Richard
    Richard almost 10 years
    It helped me, although I do echo the sentiment of posting the answer here, rather than in a link :)
  • Tizón
    Tizón almost 10 years
    Thank you, works for me! PS: very good jasdeep.ca/2013/10/installing-nokogiri-fails-os-x-mavericks
  • superluminary
    superluminary almost 10 years
    Doh, yes, I had neglected to install the XCode command line tools on my clean Mavericks install.
  • sparrow
    sparrow almost 10 years
    Perfect. Exactly what I needed. +1
  • jmg
    jmg over 9 years
    Had to add --use-system-libraries. Than it worked on a brand new mavericks installation with Xcode 5.1.1 and brew.
  • Volte
    Volte over 9 years
    would gem install nokogiri -- --use-system-libraries help?
  • Maverick
    Maverick over 9 years
    Had to add the --use-system-libraries to get this to work: gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Develop‌​er/Platforms/MacOSX.‌​platform/Developer/S‌​DKs/MacOSX10.9.sdk/u‌​sr/include/libxml2 --use-system-libraries
  • Tim
    Tim over 9 years
    Cool. Now that you are using rvm on mavericks try opening vim. SEGV error? Lovely.
  • Brian Hempel
    Brian Hempel over 9 years
    With bundler, I used bundle config build.nokogiri --with-iconv-dir=/Applications/Xcode.app/Contents/Developer/‌​Platforms/MacOSX.pla‌​tform/Developer/SDKs‌​/MacOSX10.9.sdk/usr
  • Ben
    Ben over 9 years
    i had a similar issue (an unlinked libiconv). I unlinked libiconv, and reinstalled. brew install libiconv, then gem install nokogirl.
  • Rogerio Chaves
    Rogerio Chaves over 9 years
    after googling it for hours, that was the only solution that worked for me, thanks! :D
  • KonstantinK
    KonstantinK over 9 years
    amazingly this is the only thing in this entire tread that helped me too. thanks!
  • Tod Birdsall
    Tod Birdsall over 9 years
    This worked for me: gem install nokogiri -- --use-system-libraries
  • PJP
    PJP over 9 years
    The problem with this is, using sudo with RVM or rbenv will cause problems as root doesn't know where the sandboxed Rubies live. This is covered in the RVM installation page. The OP is using RVM, and using sudo would cause Nokogiri to install into Apple's Ruby, not the user's. So, don't do this unless you are SURE you want to install into Apple's Ruby if you're on Mac OS, or into the system Ruby if you're on another *nix.
  • PJP
    PJP over 9 years
    Using sudo will cause Nokogiri to be installed in the only Ruby known by root, which is highly likely to be Apple's installed Ruby unless using Homebrew. Because the OP was using RVM, that means Nokogiri wouldn't be seen by a RVM managed Ruby, and would only compound the problem. Using sudo might have worked in this case, but it should not be tried with a RVM or rbenv managed Ruby. RVM specifically says not to do it in the installation documentation.
  • PJP
    PJP over 9 years
    This is what is considered a Link-only answer which are discouraged on Stack Overflow. Instead of only posting a link to your own site, also summarize the important information in your answer. That way, if the link rots, like they tend to do, the answer will continue to provide some value.
  • Josh
    Josh about 9 years
    This worked for me, i tried about 50 SO threads and this was the only one that worked... osx 10.10.3
  • Amax
    Amax about 9 years
    you're such a lifesaver!
  • Erik Villegas
    Erik Villegas about 9 years
    This is the only one that would work for me, on 10.10.3: sudo gem install nokogiri -- --with-iconv-lib=/Applications/Xcode.app/Contents/Developer/‌​Platforms/MacOSX.pla‌​tform/Developer/SDKs‌​/MacOSX10.10.sdk/usr‌​/lib --with-iconv-include=/Applications/Xcode.app/Contents/Develo‌​per/Platforms/MacOSX‌​.platform/Developer/‌​SDKs/MacOSX10.10.sdk‌​/usr/include --with-xml2-include=/Applications/Xcode.app/Contents/Develop‌​er/Platforms/MacOSX.‌​platform/Developer/S‌​DKs/MacOSX10.10.sdk/‌​usr/include/libxml2 --use-system-libraries
  • MattL
    MattL almost 9 years
    Worked for me on Yosemite too. None of the above answers did.
  • Durul Dalkanat
    Durul Dalkanat over 8 years
    you should use this command . open terminal. and Write this command. export NOKOGIRI_USE_SYSTEM_LIBRARIES=true
  • Arian Faurtosh
    Arian Faurtosh over 8 years
    This post being updated for El Capitan makes me happy.
  • Philipp
    Philipp over 8 years
    You may want to update your answer with the more generic command that should work across all OS X versions and Xcode install paths: gem install nokogiri -- --with-xml2-include=`xcrun --show-sdk-path`/usr/include/libxml2 --use-system-libraries
  • Dex
    Dex over 8 years
    The command for El Capitan worked for me as well to install -v '1.6.6.2'. Thank you!
  • Onikoroshi
    Onikoroshi over 7 years
    I couldn't remove the gemset because the folders weren't empty, but reinstalling the gemset (even though there were errors) did! This is the only thing that worked for me!