ruby on rails - 问题捆绑安装nokogiri 1.7.2 on ruby on rails 4.x.

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby on rails - 问题捆绑安装nokogiri 1.7.2 on ruby on rails 4.x.相关的知识,希望对你有一定的参考价值。

我有问题尝试捆绑安装nokogiri 1.7.2

我在用

gem 'rails', '4.2.4'
MacOS High Sierra version 10.13.6

我不知道出了什么问题

下面是我的错误输出:

完整错误输出:

https://gist.github.com/axilaris/68e7df57c3e29366d7a1998eebd93517

这是错误描述的地方:

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

In Gemfile:
  rails_admin was resolved to 1.1.1, which depends on
    rails was resolved to 4.2.4, which depends on
      actionmailer was resolved to 4.2.4, which depends on
        actionpack was resolved to 4.2.4, which depends on
          actionview was resolved to 4.2.4, which depends on
            rails-dom-testing was resolved to 1.0.8, which depends on
              nokogiri

更新,没有使用sudo gem install nokogiri

$ sudo gem install nokogiri -v '1.7.2'
Building native extensions.  This could take a while...

....

Building Nokogiri with a packaged version of libxml2-2.9.4
with the following patches applied:
    - 0001-Fix-comparison-with-root-node-in-xmlXPathCmpNodes.patch
    - 0002-Fix-XPointer-paths-beginning-with-range-to.patch
    - 0003-Disallow-namespace-nodes-in-XPointer-ranges.patch

Team Nokogiri will keep on doing their best to provide security
updates in a timely manner, but if this is a concern for you and want
to use the system library instead; abort this installation process and
reinstall nokogiri as follows:

    gem install nokogiri -- --use-system-libraries
        [--with-xml2-config=/path/to/xml2-config]
        [--with-xslt-config=/path/to/xslt-config]

If you are using Bundler, tell it to use the option:

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

Note, however, that nokogiri is not fully compatible with arbitrary
versions of libxml2 provided by OS/package vendors.
************************************************************************
Extracting libxml2-2.9.4.tar.gz into tmp/x86_64-apple-darwin17/ports/libxml2/2.9.4... OK
Running git apply with /Library/Ruby/Gems/2.3.0/gems/nokogiri-1.7.2/patches/libxml2/0001-Fix-comparison-with-root-node-in-xmlXPathCmpNodes.patch... OK
Running git apply with /Library/Ruby/Gems/2.3.0/gems/nokogiri-1.7.2/patches/libxml2/0002-Fix-XPointer-paths-beginning-with-range-to.patch... OK
Running git apply with /Library/Ruby/Gems/2.3.0/gems/nokogiri-1.7.2/patches/libxml2/0003-Disallow-namespace-nodes-in-XPointer-ranges.patch... OK
Running 'configure' for libxml2 2.9.4... OK
Running 'compile' for libxml2 2.9.4... ERROR, review '/Library/Ruby/Gems/2.3.0/gems/nokogiri-1.7.2/ext/nokogiri/tmp/x86_64-apple-darwin17/ports/libxml2/2.9.4/compile.log' to see what happened. Last lines are:
...

也许与此相关? https://github.com/sparklemotion/nokogiri/issues/1690

更新18.9.2018

我注意到笔记本电脑上的rails环境存在重大问题。我试图创建一个新的rails应用程序。 nokogiri给我的环境带来了重大问题。问题是什么以及如何解决这个问题? https://gist.github.com/axilaris/03882e15d2cbd603279a654547752f9c

答案

有时也会发生在我身上,在这种情况下,我只是通过gem install nokogiri -v '1.7.2'安装nokogiri,因为错误表明。如果失败,请先尝试gem uninstall nokogiri -v '1.7.2'并重试...

正如xploshioOn所提到的,使用sudo gem install作为最后的手段。

另一答案

有时这是一种痛苦,我甚至不确定为什么这种情况会随机发生。但是,这是我大部分时间都在解决的问题。

brew unlink xz
gem install nokogiri
brew link xz

如果这没有用,请使用libxml2再次抛出错误,您应该执行以下操作

brew install libxml2

然后

gem install nokogiri -- --use-system-libraries 
  --with-xml2-include=$(brew --prefix libxml2)/include/libxml2
另一答案

您可以允许bundler再次使用解析依赖关系

  • 运行brew upgrade libxml2
  • 删除Gemfile.lock文件中的块代码,从rails_admin开始直到下一个空白行
  • 保存文件
  • 运行bundle install
另一答案

有一次,在我接受xCode的许可协议之前,我的Mac找不到libxml2库:

sudo xcodebuild -license accept

您可能还想鼓励机器使用xCode libxml2:

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/

以上是关于ruby on rails - 问题捆绑安装nokogiri 1.7.2 on ruby on rails 4.x.的主要内容,如果未能解决你的问题,请参考以下文章

ruby on rails 4 - 捆绑安装grape-jbuilder

Ruby on rails 错误捆绑器

Ruby on Rails。捆绑器。黄瓜。耙中止!命令失败,状态为 (1)

使用 Ruby On Rails 4.2.5.1 我可以 gem install therubyracer 但捆绑包在 OS X 10.11.1 上失败

Ruby on Rails Eventmachine 段错误

Rails:安装 ruby​​racer 时出错