安装nokogiri(1.6.0)时出现错误,Bundler无法继续。

7
我尝试打开Rails控制台,但遇到了以下错误:
rails c
Could not find nokogiri-1.6.0 in any of the sources
Run `bundle install` to install missing gems.

然后我运行 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.

我的 Ruby 版本:

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

OS:

OSX Yosemite 10.10.1

希望有人能帮助我!谢谢。


看起来你在 Gemfile.lock 中使用了不同的 Nokogiri 版本。 - Masudul
是的,我找到了两个版本:nokogiri (~> 1.4)nokogiri (1.6.0) - pangpang
尝试将Gemfile.lock中的1.4编辑为1.6.0,然后再次运行bundle install。 - Masudul
还是同样的错误,我应该将nokogiri 1.6.0更改为其他版本吗? - pangpang
5个回答

27

我删除了 Gemfile.lock,然后运行了 bundle install。一切都没问题! :)


是的,应该删除Gemfile.lock文件。 - Don Lee
4
删除 gemfile.lock 会使得你失去对已安装gem的任何引用,如果没有在 Gemfile 中正确声明,更新版本可能会破坏一些代码。只有在允许破坏代码时才应这样做。 - Fabian de Pabian
删除 Gemfile.lock 并运行 bundle install 工作正常。谢谢。 - Kiran Mahale
你能分享一下删除 Gemfile.lock 的步骤吗?(我有很多个 Gemfiles..) - A. Trejo
1
@A.Trejo 你的项目根目录 - pangpang
今天这个甚至在我的Rails 7应用程序中也起作用了! - Tintin81

8
我曾遇到这个错误,以下是解决方法:
```html

我曾遇到这个错误,以下是解决方法:

```
bundle config build.nokogiri --use-system-libraries
bundle install

2

需要执行以下命令:sudo apt-get install build-essential patch ruby-dev zlib1g-dev liblzma-dev,然后再试着安装。


4
我们考虑加上一个“为什么?”来解释我们这样做的原因。 - lazycipher
这是macOS而不是Linux。 - geotheory

1

Run

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

那么

$ gem install nokogiri

2
我们加上一个“为什么?”来解释我们正在做什么,怎么样? - lazycipher
这是 macOS 不是 Linux。 - geotheory

0

对我来说,这是一项工作

bundle config build.nokogiri --use-system-libraries
bundle install

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接