【问题标题】:Nokogiri issues with Ruby on RailsRuby on Rails 的 Nokogiri 问题
【发布时间】:2015-11-28 05:42:45
【问题描述】:

我正在尝试在我的机器上安装 nokogiri,但收到以下错误:

Building native extensions.  This could take a while...
ERROR:  Error installing nokogiri:
    ERROR: Failed to build gem native extension.

    current directory: /Users/username/.rbenv/versions/2.0.0-p481/lib/ruby/gems/2.0.0/gems/nokogiri-1.6.6.4/ext/nokogiri
/Users/username/.rbenv/versions/2.0.0-p481/bin/ruby -r ./siteconf20151127-29540-11ahx4h.rb extconf.rb
checking if the C compiler accepts ... *** 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/username/.rbenv/versions/2.0.0-p481/bin/ruby
    --help
    --clean
/Users/username/.rbenv/versions/2.0.0-p481/lib/ruby/2.0.0/mkmf.rb:434:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /Users/username/.rbenv/versions/2.0.0-p481/lib/ruby/2.0.0/mkmf.rb:549:in `block in try_compile'
    from /Users/username/.rbenv/versions/2.0.0-p481/lib/ruby/2.0.0/mkmf.rb:500:in `with_werror'
    from /Users/username/.rbenv/versions/2.0.0-p481/lib/ruby/2.0.0/mkmf.rb:549:in `try_compile'
    from extconf.rb:80:in `nokogiri_try_compile'
    from extconf.rb:87:in `block in add_cflags'
    from /Users/username/.rbenv/versions/2.0.0-p481/lib/ruby/2.0.0/mkmf.rb:599:in `with_cflags'
    from extconf.rb:86:in `add_cflags'
    from extconf.rb:337:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Users/username/.rbenv/versions/2.0.0-p481/lib/ruby/gems/2.0.0/extensions/x86_64-darwin-14/2.0.0-static/nokogiri-1.6.6.4/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/username/.rbenv/versions/2.0.0-p481/lib/ruby/gems/2.0.0/gems/nokogiri-1.6.6.4 for inspection.
Results logged to /Users/username/.rbenv/versions/2.0.0-p481/lib/ruby/gems/2.0.0/extensions/x86_64-darwin-14/2.0.0-static/nokogiri-1.6.6.4/gem_make.out

我不确定如何解决这个问题,因为我在设置原生扩展方面没有太多经验。任何帮助将不胜感激。让我知道是否需要提供更多信息。

【问题讨论】:

  • 错误日志指出您必须安装开发工具。尝试通过运行 xcode-select --install 来安装它们 - 希望对您有所帮助。
  • 我试过了,我所有的工具都安装好了。它响应如下:xcode-select: error: command line tools are already installed, use "Software Update" to install updates。所以我运行了软件更新,重新启动并尝试安装 nokogiri。仍然收到完全相同的错误消息。
  • 您接受许可协议了吗?试试sudo xcodebuild -license 或者直接打开xcode
  • 您是否从 devkit 目录执行了dk.rb?至少在 Windows 上这是必需的步骤...

标签: ruby-on-rails ruby nokogiri


【解决方案1】:

这似乎是一个常见问题。您可以查看以下链接

http://www.nokogiri.org/tutorials/installing_nokogiri.html

您需要将 Rubygems 更新到 2.4.5 或更高版本,并检查您的电脑上是否安装了开发工具。

或者,如果您正在使用捆绑包,您可以执行以下操作

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

【讨论】:

    【解决方案2】:

    我必须使用 1.6.7.rc4-x64-mingw32 版本(我在 Windows 上)。在我的 Gemfile 中添加了这一行:

    gem 'nokogiri', '~> 1.6', '>= 1.6.7.rc4'
    

    【讨论】:

      【解决方案3】:

      在结合了来自 git 问题和 SO 的许多解决方案之后,这对我有用:

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

      虽然我确实添加了sudo

      【讨论】:

      • 安装 gems 时不要使用sudo。这会导致它修改 Apple 安装的 Ruby。相反,请使用 RVM 或 rbenv 来管理新的 Ruby,然后您可以根据自己的喜好对其进行修改。
      • 我知道,我只是提过而已。我现在已经安装了 RVM,我所有的 OS X Ruby 问题都解决了。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多