2015-11-28 106 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問題。 –