当我运行bundle install时,Nokogiri'无法构建gem native extension'

问题描述 投票:66回答:16

我正在运行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.

任何想法可能是什么?

EDIT:

我也在instructions in the tutorial之后安装了nokogiri,奇怪的是宝石已成功安装。当我运行gem list时,我有nokogiri (1.6.2.1),但在运行bundle install时会显示错误。

ruby-on-rails rubygems bundle nokogiri
16个回答
227
投票

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

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

1
投票

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

使用以下命令更新Xcode Developer Tools:

xcode-select --install

然后:

gem install nokogiri

如果你通过使用修复它

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

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

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

0
投票

这个thread on GitHub给了我诀窍我需要安装Nokogiri 1.6.2:

我的〜/ .gitconfig有设置autocrlf = input。当我删除此设置时,nokogiri构建成功。


0
投票

在Yosemite 10.10上,这个解决方法对我有用:

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

0
投票

对于#CentOS,我需要执行以下操作:

gem update --system
yum install libxml2-devel libxslt-devel ruby-devel
gem install nokogiri -- --use-system-libraries

0
投票

这是一个旧的线程,但我遇到了类似的问题,我的案例中的解决方案与目前发布的解决方案完全不同。

经过一番挖掘,我找到了这个帖子:https://github.com/bundler/bundler/issues/2648#issuecomment-25124800

它讨论了使用宝石使用的不同版本的ruby的bundler。

从OP的粘贴,我们可以看到bundler正在使用ruby的Mac系统副本: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby

就我而言,我发现宝石来自酿造; which gem给了/usr/local/bin/gem哪个符号链接到/Cellar/ruby/2.3.3/bin/gem。我的猜测是OP的情况是一样的。

因此,gem和bundler没有使用相同的ruby安装,这解释了为什么OP看到了这个:

当我运行gem list时,我有nokogiri(1.6.2.1),但是当运行bundle install时会显示错误。

在我的情况下,我只是运行gem install bundler,这使得捆绑者开始使用brewy版本的ruby,所有问题都消失了。


0
投票

在OSX 10.12(Sierra)上,这对我有用:

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


0
投票

我有这个问题。我在mac上运行rails环境。在我从优胜美地升级到塞拉利昂后,我相信它开始时的情况。

要解决这个问题,我只需要安装xcode command line tools。我不知道Sierra升级版是否删除了它们或者是什么。

xcode-select --install

(这将安装xcode command line tools

另外一个症状就像git status一样不起作用。在此之后,我能够做新的appname,这很好。


51
投票

在Mavericks上,这个解决方法对我有用:

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

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


14
投票

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

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

4
投票

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

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

我不确定,确切需要哪一个。


3
投票

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

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

2
投票

在约塞米蒂10.10.1,这一步没有帮助(可能适用于其他人)

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

基本上我的本地问题是由于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

2
投票

这适用于OS X El Capitan:

brew install libxml2 libxslt libiconv 

运行'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

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

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

1
投票

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

在我的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

你有三个选择。

  1. 检查您的OS包管理器是否提供了更新版本的libxml2库
  2. 下载最新的libxml2源代码,编译并安装它
  3. 在Gemfile中手动指定旧版本的nokogiri,该版本适用于较旧的libxml2库。 nokogiri更改日志显示nokogiri版本1.4.7不会出现此问题(尽管使用旧版本可能会使您遇到安全问题)

对于解决方案#3,您可以将其放在gemfile中:gem 'nokogiri', '1.4.7'


1
投票

在Yosemite 10.10上,以下步骤完全解决了我的问题:

  • sudo xcode-select -switch /Library/Developer/CommandLineTools
  • gem uninstall nokogiri libxml-ruby
  • gem install nokogiri
© www.soinside.com 2019 - 2024. All rights reserved.