An error occurred while installing nokogiri (1.6.0), and Bundler cannot continue
Asked Answered
B

5

8

I tried to open the rails console, but found the error as below:

rails c
Could not find nokogiri-1.6.0 in any of the sources
Run `bundle install` to install missing gems.

then I run the bundle install

Installing nokogiri (1.6.0)
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /Users/liuxingqi/.rbenv/versions/1.9.3-p0/bin/ruby extconf.rb
Extracting libxml2-2.8.0.tar.gz into tmp/i686-apple-darwin11/ports/libxml2/2.8.0... OK
Running 'configure' for libxml2 2.8.0... OK
Running 'compile' for libxml2 2.8.0... OK
Running 'install' for libxml2 2.8.0... OK
Activating libxml2 2.8.0 (from /Users/liuxingqi/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/nokogiri-1.6.0/ports/i686-apple-darwin11/libxml2/2.8.0)...
Extracting libxslt-1.1.26.tar.gz into tmp/i686-apple-darwin11/ports/libxslt/1.1.26... OK
Running 'configure' for libxslt 1.1.26... OK
Running 'compile' for libxslt 1.1.26... OK
Running 'install' for libxslt 1.1.26... OK
Activating libxslt 1.1.26 (from /Users/liuxingqi/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/nokogiri-1.6.0/ports/i686-apple-darwin11/libxslt/1.1.26)...
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
    --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/liuxingqi/.rbenv/versions/1.9.3-p0/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/liuxingqi/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /Users/liuxingqi/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/mkmf.rb:506:in `try_cpp'
    from /Users/liuxingqi/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/mkmf.rb:970:in `block in find_header'
    from /Users/liuxingqi/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/mkmf.rb:790:in `block in checking_for'
    from /Users/liuxingqi/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/mkmf.rb:284:in `block (2 levels) in postpone'
    from /Users/liuxingqi/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/liuxingqi/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/mkmf.rb:284:in `block in postpone'
    from /Users/liuxingqi/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/liuxingqi/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/mkmf.rb:280:in `postpone'
    from /Users/liuxingqi/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/mkmf.rb:789:in `checking_for'
    from /Users/liuxingqi/.rbenv/versions/1.9.3-p0/lib/ruby/1.9.1/mkmf.rb:969:in `find_header'
    from extconf.rb:166:in `<main>'


Gem files will remain installed in /Users/liuxingqi/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/nokogiri-1.6.0 for inspection.
Results logged to /Users/liuxingqi/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/nokogiri-1.6.0/ext/nokogiri/gem_make.out

An error occurred while installing nokogiri (1.6.0), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.0'` succeeds before bundling.

my ruby version:

ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin14.0.0]

OS:

OSX Yosemite 10.10.1

Hope anyone can help me! Thanks.

Breathy answered 25/5, 2015 at 5:54 Comment(4)
Seams you used different nokogiri version at Gemfile.lock.Joacima
yes, I found two version: nokogiri (~> 1.4), nokogiri (1.6.0)Breathy
Try to edit Gemfile.lock 1.4 to 1.6.0 and run bundle install again.Joacima
still same error, should I change nokogiri 1.6.0 to other version?Breathy
B
29

I delete the Gemfile.lock, then run bundle install. Everything is ok! :)

Breathy answered 25/5, 2015 at 6:33 Comment(6)
Yes. Should remove Gemfile.lock.Etui
Removing the gemfile.lock makes you lose any reference to the installed gems, if not properly stated in the Gemfile the updated versions might break some code. Only do this when you are allowed to break codeFinalize
Removing Gemfile.lock and bundle install is working fine. Thanks.Mettlesome
Could you share the steps to remove this Gemfile.lock ? (I have many Gemfiles..)Titanesque
@A.Trejo the root directory of your projectBreathy
This even worked in a Rails 7 app for me today!Ahearn
T
9

I had into this error and this is what worked for me:

bundle config build.nokogiri --use-system-libraries
bundle install
Titanesque answered 18/12, 2020 at 19:34 Comment(0)
H
2

To do sudo apt-get install build-essential patch ruby-dev zlib1g-dev liblzma-dev And Try install again

Helenehelenka answered 6/9, 2018 at 4:47 Comment(2)
How about adding a "WHY?" we're doing this?Veta
This is macOS not linuxBatson
D
1

Run

$ sudo apt-get install build-essential patch ruby-dev zlib1g-dev liblzma-dev

Then

$ gem install nokogiri
Dibbrun answered 28/8, 2019 at 10:20 Comment(2)
How about adding a "WHY?" we're doing this?Veta
This is macOS not linuxBatson
F
1

For me, this work

bundle config build.nokogiri --use-system-libraries
bundle install
Fanchie answered 7/4, 2023 at 7:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.