Nokogiri issues with Ruby on Rails
Asked Answered
W

3

3

I'm trying to install nokogiri on my machine but I am receiving the following error:

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

    current directory: /Users/username/.rbenv/versions/2.0.0-p481/lib/ruby/gems/2.0.0/gems/nokogiri-1.6.6.4/ext/nokogiri
/Users/username/.rbenv/versions/2.0.0-p481/bin/ruby -r ./siteconf20151127-29540-11ahx4h.rb extconf.rb
checking if the C compiler accepts ... *** 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=/Users/username/.rbenv/versions/2.0.0-p481/bin/ruby
    --help
    --clean
/Users/username/.rbenv/versions/2.0.0-p481/lib/ruby/2.0.0/mkmf.rb:434:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /Users/username/.rbenv/versions/2.0.0-p481/lib/ruby/2.0.0/mkmf.rb:549:in `block in try_compile'
    from /Users/username/.rbenv/versions/2.0.0-p481/lib/ruby/2.0.0/mkmf.rb:500:in `with_werror'
    from /Users/username/.rbenv/versions/2.0.0-p481/lib/ruby/2.0.0/mkmf.rb:549:in `try_compile'
    from extconf.rb:80:in `nokogiri_try_compile'
    from extconf.rb:87:in `block in add_cflags'
    from /Users/username/.rbenv/versions/2.0.0-p481/lib/ruby/2.0.0/mkmf.rb:599:in `with_cflags'
    from extconf.rb:86:in `add_cflags'
    from extconf.rb:337:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Users/username/.rbenv/versions/2.0.0-p481/lib/ruby/gems/2.0.0/extensions/x86_64-darwin-14/2.0.0-static/nokogiri-1.6.6.4/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/username/.rbenv/versions/2.0.0-p481/lib/ruby/gems/2.0.0/gems/nokogiri-1.6.6.4 for inspection.
Results logged to /Users/username/.rbenv/versions/2.0.0-p481/lib/ruby/gems/2.0.0/extensions/x86_64-darwin-14/2.0.0-static/nokogiri-1.6.6.4/gem_make.out

I'm unsure how to go about fixing this as I do not have too much experience with setting up native extensions. Any help would be greatly appreciated. Let me know if more information needs to be presented.

Winegrower answered 28/11, 2015 at 5:42 Comment(4)
The error log states that you have to install development tools. Try installing them by running xcode-select --install - hope that helps.Ashjian
I tried this and all of my tools are installed. It responds with the following: xcode-select: error: command line tools are already installed, use "Software Update" to install updates. So I ran a software update, restarted and tried to install nokogiri. Still getting the exact same error message.Winegrower
Have you accepted the license agreement? Try sudo xcodebuild -license or just open xcodeWollastonite
Did you execute dk.rb from the devkit directory? At least on Windows that is a required step...Frazzled
P
1

This seems to be a common issue. You can check the following link

http://www.nokogiri.org/tutorials/installing_nokogiri.html

You will need to update the Rubygems to 2.4.5 or later and also check whether development tools is installed on you pc.

Or you can do the following if you are using bundle

gem update --system
gem install nokogiri -- --use-system-libraries
bundle config build.nokogiri --use-system-libraries
bundle install
Patron answered 28/11, 2015 at 7:23 Comment(0)
G
0

I had to use version 1.6.7.rc4-x64-mingw32 (I'm on Windows). Added this line to my Gemfile:

gem 'nokogiri', '~> 1.6', '>= 1.6.7.rc4'
Griffy answered 29/11, 2015 at 1:54 Comment(0)
B
0

After combining many solutions from git issues and SO, this worked for me:

gem install nokogiri -v '1.6.7' -n /usr/local/bin -- --use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib/

Although I did prepend sudo.

Branching answered 30/12, 2015 at 5:31 Comment(2)
Don't use sudo when installing gems. That causes it to modify the Ruby installed by Apple. Instead, use RVM or rbenv to manage a new Ruby, which you can then modify to your heart's content.Match
I know, I was just mentioning since I did. I have now installed RVM and all my OS X Ruby issue are solved.Branching

© 2022 - 2024 — McMap. All rights reserved.