Ruby-on-rails 当我运行 bundle install 时,Nokogiri“无法构建 gem 本机扩展”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23668684/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 23:37:49  来源:igfitidea点击:

Nokogiri 'Failed to build gem native extension' when I run bundle install

ruby-on-railsrubygemsbundlenokogiri

提问by FabKremer

I'm running bundle installand I'm getting this error:

我正在运行bundle install,但出现此错误:

Building nokogiri using system libraries.

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

    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb --use-system-libraries
Building nokogiri using system libraries.
libxml2 version 2.6.21 or later is required!
*** 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=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
    --help
    --clean
    --use-system-libraries
    --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-xml2-dir
    --without-xml2-dir
    --with-xml2-include
    --without-xml2-include=${xml2-dir}/include
    --with-xml2-lib
    --without-xml2-lib=${xml2-dir}/lib
    --with-libxml-2.0-config
    --without-libxml-2.0-config
    --with-pkg-config
    --without-pkg-config
    --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-exslt-dir
    --without-exslt-dir
    --with-exslt-include
    --without-exslt-include=${exslt-dir}/include
    --with-exslt-lib
    --without-exslt-lib=${exslt-dir}/lib
    --with-libexslt-config
    --without-libexslt-config
    --with-pkg-config
    --without-pkg-config

extconf failed, exit code 1

Gem files will remain installed in /Users/myuser/projectpath/vendor/bundle/ruby/2.0.0/gems/nokogiri-1.6.2.rc2 for inspection.
Results logged to /Users/myuser/projectpath/vendor/bundle/ruby/2.0.0/extensions/universal-darwin-13/2.0.0/nokogiri-1.6.2.rc2/gem_make.out
An error occurred while installing nokogiri (1.6.2.rc2), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.2.rc2'` succeeds before bundling.

Any ideas what could this be?

任何想法这可能是什么?

EDIT:

编辑:

I also have installed nokogiri following the instructions in the tutorial, and the weird thing is that the gem was successfully installed. When I run gem list, I have nokogiri (1.6.2.1), but when running bundle installit displays the error.

我也按照教程中说明安装了 nokogiri ,奇怪的是 gem 安装成功。当我运行时gem list,我有nokogiri (1.6.2.1),但运行bundle install时显示错误。

回答by Kir

Previous advises didn't help me, here is the solution for OS 10.9:

以前的建议对我没有帮助,这是 OS 10.9 的解决方案:

brew install libxml2
bundle config build.nokogiri "--use-system-libraries --with-xml2-include=/usr/local/opt/libxml2/include/libxml2"
bundle install

回答by pcv

On Mavericks this workaround worked for me:

在小牛队上,这种解决方法对我有用:

gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2

See: https://github.com/sparklemotion/nokogiri/issues/1099#issuecomment-43023208

参见:https: //github.com/sparklemotion/nokogiri/issues/1099#issuecomment-43023208

回答by andrewtweber

On Amazon Linux, I had to install these two devel libraries, and then specify the include path for libxml2

在 Amazon Linux 上,我必须安装这两个开发库,然后指定 libxml2 的包含路径

$ yum install libxml2-devel libxslt-devel
$ gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/usr/include/libxml2/

回答by Saurabh

I also had some problems installing nokogiri, Than I installed following packages, It worked for me:

我在安装 nokogiri 时也遇到了一些问题,我安装了以下软件包,它对我有用:

libxslt-dev
libxml2-dev
libruby1.8
libreadline-ruby1.8
libopenssl-ruby
libxml2

I am not sure, which one was exactly needed.

我不确定,究竟需要哪一个。

回答by dTron

http://nokogiri.org/tutorials/installing_nokogiri.html. Refer to this link and install the dependencies required for nokogiri. Then run this

http://nokogiri.org/tutorials/installing_nokogiri.html。请参阅此链接并安装 nokogiri 所需的依赖项。然后运行这个

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

回答by Rohan Daxini

On Yosemite 10.10.1, this step did not help (may be it works for others)

在优胜美地 10.10.1 上,这一步没有帮助(可能对其他人有用)

gem install nokogiri -- --use-system-libraries

Basically issue on my local was due to libxml2, so following workaround did the trick

基本上我本地的问题是由于libxml2,所以以下解决方法可以解决问题

bundle config build.nokogiri "--use-system-libraries --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/libxml2

bundle install

回答by DaedalusZ

This worked for OS X El Capitan:

这适用于 OS X El Capitan:

brew install libxml2 libxslt libiconv 

After running the'brew install libxml2 libxslt libiconv ' You may find, that they are already installed. No worries, it never hurts to double check.

运行 'brew install libxml2 libxslt libiconv ' 后,您可能会发现它们已经安装。不用担心,仔细检查永远不会有什么坏处。

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

bundle install

Change the version of nokogiri, if needed. e.g.

如果需要,更改 nokogiri 的版本。例如

sudo gem install nokogiri -v '1.6.5' -- --use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib

回答by Kay Wu

For mac, the reason why it failed is that you didn't have latest Xcode Developer Tools. Nokogiri has already been packaged with libxml2. For the lack of latest Xcode Developer Tools, it can't build native extensions.

对于 mac,失败的原因是你没有最新的 Xcode Developer Tools。Nokogiri 已经与 libxml2 一起打包。由于缺少最新的 Xcode Developer Tools,它无法构建原生扩展。

To update Xcode Developer Tools using:

要使用以下方法更新 Xcode 开发人员工具:

xcode-select --install

And then:

进而:

gem install nokogiri

If you fix it by using

如果您通过使用修复它

gem install nokogiri -- --use-system-libraries

may get a similar warning later:

稍后可能会收到类似的警告:

WARNING: Nokogiri was built against LibXML version 2.9.3, but has dynamically loaded 2.9.0

回答by Ulan Assanov

On Yosemite 10.10 the following steps solved my issues completely:

在优胜美地 10.10 上,以下步骤完全解决了我的问题:

  • sudo xcode-select -switch /Library/Developer/CommandLineTools
  • gem uninstall nokogiri libxml-ruby
  • gem install nokogiri
  • sudo xcode-select -switch /Library/Developer/CommandLineTools
  • gem uninstall nokogiri libxml-ruby
  • gem install nokogiri

回答by Martin Konecny

The error states that your libxml2 system library is out of date. You need version 2.6.21 or later.

该错误指出您的 libxml2 系统库已过期。您需要 2.6.21 或更高版本。

On my Debian/ubuntu system, nokogiri compiles for me, and I can see I have version 2.9.1

在我的 Debian/ubuntu 系统上,nokogiri 为我编译,我可以看到我有 2.9.1 版

dpkg -l | grep libxml2-dev
ii  libxml2-dev:amd64                      2.9.1+dfsg1-3                      amd64        Development files for the GNOME XML library

You have three options here.

您在这里有三个选择。

  1. Check if your OS package manager provides a newer version of libxml2 library

  2. Download the latest libxml2 source code, compile and install it

  3. Manually specify an older version of nokogiri in your Gemfile that works with older libxml2 library. The nokogiri changelog shows that you won't have this problem with nokogiri version 1.4.7 (although using an older version can expose you to security issues)
  1. 检查您的操作系统包管理器是否提供了较新版本的 libxml2 库

  2. 下载最新的libxml2源码,编译安装

  3. 在您的 Gemfile 中手动指定一个旧版本的 nokogiri,它可以与旧的 libxml2 库一起使用。nokogiri 更新日志显示 nokogiri 版本 1.4.7 不会出现此问题(尽管使用旧版本会使您面临安全问题)

For solution #3, you would put this in your gemfile: gem 'nokogiri', '1.4.7'

对于解决方案 #3,你可以把它放在你的 gemfile 中: gem 'nokogiri', '1.4.7'