Error to install Nokogiri on OSX 10.9 Maverick?
Asked Answered
J

30

110

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?

Joesphjoete answered 28/10, 2013 at 19:11 Comment(2)
possible duplicate of Error installing nokogiri 1.6.0 on mac (libxml2)Genesisgenet
Try opening xcode and accept the EULA/license.Possing
J
20

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

Joesphjoete answered 28/10, 2013 at 19:55 Comment(10)
this didn't solve the issue for me, i still have the same error message :(Hideout
I completely uninstalled rvm and ruby (from brew), installed again, and it worked.Hideout
Does it not compile using clang?Arni
How did you compile apple-gcc42 then? It must be easier to use the "default" compiler than to install a new (old) one?Arni
So, I just run brew install apple-gcc42.. and just works. That command don't work for you?Joesphjoete
I ran xcode-select --install before the brew install and all works now.Sepalous
@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.Saundra
@LucyBain I realy don't remember.... but I think that log file was in same directory as gem_meake.out...Joesphjoete
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.Reciprocity
would gem install nokogiri -- --use-system-libraries help?Heptad
G
243

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
Gestate answered 6/11, 2013 at 8:50 Comment(10)
Not for me: "libxml2 is missing. please visit nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies." Still getting same error.Bailsman
Had to add --use-system-libraries. Than it worked on a brand new mavericks installation with Xcode 5.1.1 and brew.Tincture
Had to add the --use-system-libraries to get this to work: gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2 --use-system-librariesRosettarosette
With bundler, I used bundle config build.nokogiri --with-iconv-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usrSinistrality
This worked for me: gem install nokogiri -- --use-system-librariesSaving
This worked for me, i tried about 50 SO threads and this was the only one that worked... osx 10.10.3Towne
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.platform/Developer/SDKs/MacOSX10.10.sdk/usr/lib --with-iconv-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/libxml2 --use-system-librariesFinery
This post being updated for El Capitan makes me happy.Chromato
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-librariesSherrill
The command for El Capitan worked for me as well to install -v '1.6.6.2'. Thank you!Proclus
M
30

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

Maighdlin answered 13/2, 2014 at 5:45 Comment(2)
Thank you, works for me! PS: very good jasdeep.ca/2013/10/installing-nokogiri-fails-os-x-mavericksPollack
Doh, yes, I had neglected to install the XCode command line tools on my clean Mavericks install.Mccready
J
20

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

Joesphjoete answered 28/10, 2013 at 19:55 Comment(10)
this didn't solve the issue for me, i still have the same error message :(Hideout
I completely uninstalled rvm and ruby (from brew), installed again, and it worked.Hideout
Does it not compile using clang?Arni
How did you compile apple-gcc42 then? It must be easier to use the "default" compiler than to install a new (old) one?Arni
So, I just run brew install apple-gcc42.. and just works. That command don't work for you?Joesphjoete
I ran xcode-select --install before the brew install and all works now.Sepalous
@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.Saundra
@LucyBain I realy don't remember.... but I think that log file was in same directory as gem_meake.out...Joesphjoete
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.Reciprocity
would gem install nokogiri -- --use-system-libraries help?Heptad
G
15

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
Gramnegative answered 28/3, 2014 at 3:56 Comment(0)
R
12

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
Recreation answered 18/5, 2014 at 8:42 Comment(2)
amazingly this is the only thing in this entire tread that helped me too. thanks!Hyalo
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.Companion
F
10

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.

Fabi answered 2/5, 2014 at 15:48 Comment(2)
Cool. Now that you are using rvm on mavericks try opening vim. SEGV error? Lovely.Ducks
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!Cruelty
B
9

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/
Belia answered 11/8, 2014 at 1:39 Comment(1)
after googling it for hours, that was the only solution that worked for me, thanks! :DWhitewall
H
5

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.

Hinckley answered 27/9, 2014 at 20:55 Comment(0)
M
3

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!

Medievalist answered 21/9, 2014 at 7:55 Comment(1)
Worked for me on Yosemite too. None of the above answers did.Mangan
F
3

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
Fancywork answered 7/10, 2016 at 13:54 Comment(0)
A
2

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
Aleksandr answered 22/11, 2013 at 14:9 Comment(2)
I had to be very meticulous with the filepaths. It took me multiple tries to correctly construct the commands.Aleksandr
Here's a link to another solution to the issue of an incorrect libxml version.Aleksandr
I
2

Use brew install libxml2 libxslt if you use Homebrew.

Interject answered 30/7, 2014 at 7:4 Comment(0)
S
2

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.

Shenika answered 15/12, 2014 at 9:59 Comment(0)
C
2

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
Crocket answered 19/3, 2015 at 1:34 Comment(0)
F
2

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.

Fennelly answered 7/5, 2015 at 5:31 Comment(0)
S
1

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.

Scurf answered 5/11, 2013 at 23:16 Comment(0)
T
1

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.

Tanager answered 26/11, 2013 at 8:9 Comment(2)
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.Joesphjoete
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.Tanager
O
1

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.

Oriental answered 3/12, 2013 at 8:38 Comment(0)
S
1

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.

Snowbound answered 5/12, 2013 at 21:21 Comment(3)
Please post the stuff here - links are liable to be broken (see the guidelines)Portiaportico
It helped me, although I do echo the sentiment of posting the answer here, rather than in a link :)Directorial
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.Companion
L
1

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
Languishment answered 14/5, 2014 at 10:9 Comment(0)
F
1
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/*
Funk answered 26/5, 2014 at 15:3 Comment(0)
A
1

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.

Angioma answered 30/5, 2014 at 12:10 Comment(0)
P
1

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 
Perez answered 29/9, 2014 at 14:21 Comment(0)
N
1

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
Noleta answered 28/1, 2016 at 8:19 Comment(0)
M
1

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.

Minimize answered 24/5, 2016 at 5:2 Comment(0)
C
0

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
Cupro answered 8/12, 2013 at 16:15 Comment(1)
i had a similar issue (an unlinked libiconv). I unlinked libiconv, and reinstalled. brew install libiconv, then gem install nokogirl.Fredela
P
0

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
Panslavism answered 12/12, 2014 at 21:50 Comment(1)
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.Companion
W
0

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.

Widener answered 6/1, 2016 at 0:14 Comment(0)
A
0

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!

Arethaarethusa answered 3/1, 2017 at 18:34 Comment(0)
W
-3

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

gem install nokogiri
Wittol answered 1/6, 2014 at 6:5 Comment(1)
you should use this command . open terminal. and Write this command. export NOKOGIRI_USE_SYSTEM_LIBRARIES=trueRoxannaroxanne

© 2022 - 2024 — McMap. All rights reserved.