2015-11-28 79 views
2

我想在我的机器上安装引入nokogiri但我收到以下错误:引入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 

我不知道该如何去修复这个,因为我没有做太多在设置本地扩展方面有很多经验。任何帮助将不胜感激。让我知道是否需要提供更多信息。

+0

错误日志指出您必须安装开发工具。尝试通过运行'xcode-select --install'来安装它们 - 希望有所帮助。 – Zoran

+0

我试过了,我的所有工具都已安装。它的响应如下:'xcode-select:error:命令行工具已经安装,使用“软件更新”安装更新'。所以我跑了一个软件更新,重新启动并试图安装nokogiri。仍然收到完全相同的错误消息。 – Nappstir

+1

你接受了许可协议吗?试试'sudo xcodebuild -license'或者只是打开xcode – amree

回答

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 
0

我不得不使用版本1.6.7.rc4-x64的mingw32的(我在Windows上)执行以下操作。该行添加到我的Gemfile:

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

许多解决方案,从git的问题相结合后是这样,这个工作对我来说:

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

+0

安装宝石时不要使用'sudo'。这会导致它修改Apple安装的Ruby。相反,使用RVM或rbenv来管理一个新的Ruby,然后你可以修改你的内容。 –

+0

我知道,自从我这样做之后,我只是提到了。我现在已经安装了RVM,并解决了我所有的OS X Ruby问题。 –