Issues installing Nokogiri 1.6.5 on OS X Yosemite (10.10.1) #1210

Closed
adamdullenty opened this Issue Dec 17, 2014 · 16 comments

Projects

None yet

7 participants

@adamdullenty

Hey,

I recently followed this guide to get my brand new MacBook set up in the same way as my Ubuntu box, but switching to chruby instead of rvm:

http://andycroll.com/mac/ruby/the-simplest-possible-serious-ruby-on-rails-setup-on-mavericks/

So my environment should be pretty clean.

However when trying to 'bundle install' I'm getting the following error for Nokogiri:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /Users/me/.rubies/ruby-2.1.3/bin/ruby extconf.rb 

/Users/me/.rubies/ruby-2.1.3/bin/ruby: invalid option -2  (-h will show valid options) (RuntimeError)

extconf failed, exit code 1

Gem files will remain installed in /Users/me/.gem/ruby/2.1.3/gems/nokogiri-1.6.5 for inspection.

Results logged to /Users/me/.gem/ruby/2.1.3/extensions/x86_64-darwin-14/2.1.0-static/nokogiri-1.6.5/gem_make.out

An error occurred while installing nokogiri (1.6.5), and Bundler cannot

continue.

Since then I have tried all of the relevant code snippets on here http://www.nokogiri.org/tutorials/installing_nokogiri.html with again no luck (and the error message I am seeing is different to the one highlighted on that page anyway)

Fairly new to OS X and Macs in general so not overly sure how to proceed.

Any ideas would be gratefully received.

@juliosousa

I had a lot of trouble with this installation, but it solved for me:

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

@adamdullenty

No luck with that unfortunately, similar error:

Building native extensions with: '--use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2- lib=/usr/lib/'
This could take a while...
ERROR:  Error installing nokogiri:
    ERROR: Failed to build gem native extension.

    /Users/me/.rubies/ruby-2.1.3/bin/ruby extconf.rb --use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2- lib=/usr/lib/
/Users/me/.rubies/ruby-2.1.3/bin/ruby: invalid option -2  (-h will show valid options) (RuntimeError)

extconf failed, exit code 1

Gem files will remain installed in /Users/me/.gem/ruby/2.1.3/gems/nokogiri-1.6.5 for inspection.
@zenspider
Contributor

That "-2" is highly suspect. I don't have any idea how that'd come about. But, look at the first line:

Building native extensions with: '--use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2- lib=/usr/lib/'

That space in "with-xml2-[space]lib"? Try fixing that and trying again.

@neonichu
Contributor
neonichu commented Jan 7, 2015

There's also an issue with latest OS X / Xcode and a check introduced in version 1.6.5 of Nokogiri, see #1218

@jkxyz
jkxyz commented Jan 10, 2015

I found that this problem was fixed by running xcode-select --install and installing the command-line developer tools. I thought I had already installed them with Xcode, but I guess not.

@zenspider
Contributor

@neonichu I know of no known issue with the latest OSX/xcode if my requirements/install instructions are followed. If you have details that reproduce an error within those parameters, please let us know.

@zenspider
Contributor

I believe this ticket can be closed. I believe it was resolved on IRC. If I'm misremembering, then @adamdullenty needs to respond.

@adamdullenty

@zenspider Apologies for delay replying - no that wasn't me on IRC.

I fixed the rogue space and had the same error:

gem install nokogiri -- --use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib/
Building native extensions with: '--use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib/'
This could take a while...
ERROR:  Error installing nokogiri:
    ERROR: Failed to build gem native extension.

    /Users/adamdullenty/.rubies/ruby-2.1.3/bin/ruby extconf.rb --use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib/
/Users/adamdullenty/.rubies/ruby-2.1.3/bin/ruby: invalid option -2  (-h will show valid options) (RuntimeError)

extconf failed, exit code 1

Gem files will remain installed in /Users/adamdullenty/.gem/ruby/2.1.3/gems/nokogiri-1.6.5 for inspection.
Results logged to /Users/adamdullenty/.gem/ruby/2.1.3/extensions/x86_64-darwin-14/2.1.0-static/nokogiri-1.6.5/gem_make.out

I've since seen the same issue with other gems when gem updating - picked json randomly but it seems to be happening for loads of stuff:

Cheers.

@adamdullenty

Seems this is due to Xcode 5.1, see the accepted answer on this thread:

http://stackoverflow.com/questions/22352838/ruby-gem-install-json-fails-on-mavericks-and-xcode-5-1-unknown-argument-mul

Easiest fix for now is to set this flag before installing, but in general it looks like this option won't be there forever and gems will need updating to not use any unrecognised command line switches:

ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future
@neonichu
Contributor

@adamdullenty IIRC, this flag being required was a combination of an issue in the Ruby that shipped with 10.9 and Xcode 5.1 - it doesn't happen on 10.10 anymore.

@flavorjones
Member

I don't believe this is mac-specific, there's a post on nokogiri-talk reporting of the same issue on Ubuntu:

https://groups.google.com/d/msg/nokogiri-talk/-ajH8ho16zM/64eh9PrlW-8J

The post suggests this may be an issue with chruby ...

@adamdullenty

Might be right, and my previous post about Xcode 5.1 and the flag might have been a red herring as at the time I had switched from chruby to rvm.

@flavorjones
Member

I am unable to reproduce this, running a fresh Vagrant image of Ubuntu 14.04 x64, within which is installed

  • ruby-installer 0.5.0
  • ... which installed ruby 2.1.3p242
  • chruby 0.3.9
  • nokogiri 1.6.5

Can anyone suggest further research I can do into this problem to reproduce it?

@flavorjones flavorjones self-assigned this Jan 12, 2015
@adamdullenty

Another thing to rule out is whether RUBYOPT has been set by mistake as in
this thread:

postmodern/chruby#255

I can't remember setting this myself but on checking it it looks like it
has been erroneously set to '2.1' from somewhere.

Others having issues: try checking your RUBYOPT with "echo $RUBYOPT". If
it's set to 2.x.x (etc) it can be cleared with "unset RUBYOPT"

On Mon, Jan 12, 2015 at 2:19 PM, Mike Dalessio notifications@github.com
wrote:

I am unable to reproduce this, running a fresh Vagrant image of Ubuntu
14.04 x64, within which is installed

  • ruby-installer 0.5.0
  • ... which installed ruby 2.1.3p242
  • chruby 0.3.9
  • nokogiri 1.6.5

Can anyone suggest further research I can do into this problem to
reproduce it?


Reply to this email directly or view it on GitHub
#1210 (comment)
.

@flavorjones
Member

Closing. If you can help me reproduce this somehow, I'm happy to reopen and investigate.

Thanks for using Nokogiri!

@holms
holms commented Mar 3, 2016
gem install nokogiri -- --use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib/

This worked for me!!! Thank you!!

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