运行Bundle Install时Nokogiri v 1.8.1问题

时间:2017-10-31 15:00:05

标签: ruby-on-rails nokogiri

当运行Bundle Install或Gem Install Nokogiri时,我遇到了阻止我的应用程序运行的相同问题。我怀疑这个问题是本地的,并且是将所有内容都移到了Rails 5,但我不确定。以下是错误消息:

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

In Gemfile:
  rails_admin was resolved to 1.2.0, which depends on
    rails was resolved to 5.1.3, which depends on
      actioncable was resolved to 5.1.3, which depends on
        actionpack was resolved to 5.1.3, which depends on
          actionview was resolved to 5.1.3, which depends on
            rails-dom-testing was resolved to 2.0.3, which depends on
              nokogiri

(来自运行Bundle Install) 我已经尝试运行Bundle Update并使用Gi​​thub推荐的各种Homebrew命令,但我没有取得任何成功。

gem install nokogiri -v'1.8.1'

1 error generated.
make[2]: *** [xmlIO.lo] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
========================================================================
*** 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.

8 个答案:

答案 0 :(得分:10)

(对于UBUNTU)首先尝试这样做

sudo apt-get install build-essential patch ruby-dev zlib1g-dev liblzmadev

然后尝试安装。

答案 1 :(得分:5)

Nokogiri无法正常构建,因为你没有像libxml2这样的开发库。查看日志文件以查看发生的情况或尝试使用brew install libxml2

直接安装libxml2

请参阅Nokogiry在http://www.nokogiri.org/tutorials/installing_nokogiri.html

提供的引导指南

答案 2 :(得分:5)

我只是发布找到的解决方案(我在MacOS上也遇到了同样的问题)。这样,gem将使用系统库安装,这应该可以解决您遇到的问题。

  1. 如果使用 gem
gem install nokogiri -- --use-system-libraries
 [--with-xml2-config=/path/to/xml2-config]
 [--with-xslt-config=/path/to/xslt-config]
  1. 如果使用捆绑包
bundle config build.nokogiri --use-system-libraries
bundle install

答案 3 :(得分:2)

以下是可能有助于您解决此问题的步骤:

  1. gem update —system

  2. 安装Xcode命令行工具:xcode-select —install

  3. 最后安装Nokogiri:gem install nokogiri

答案 4 :(得分:1)

libxml2和 zlib 是构建所必需的,您需要同时安装两者。

Fedora:

sudo dnf install libxml2-devel zlib-devel

Ubuntu:

sudo apt install libxml2-dev zlib1g-dev 

答案 5 :(得分:1)

在高山脉(和莫哈韦沙漠)上,这对我有用

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

bundle update

bundle install

答案 6 :(得分:0)

升级Xcode后出现相同的问题

我必须跑步:sudo xcode-select --switch /Library/Developer/CommandLineTools/ then: sudo bundle install --system

那之后一切都很好。

答案 7 :(得分:0)

如果使用MAC OS 您可以尝试

brew unlink xz
gem install nokogiri
brew link xz

我使用MAC OS,并使用brew install ruby避免弄乱系统的ruby环境,随后的bundle install进行得非常顺利。