Gem文件不会使用bundler更新或安装

时间:2014-08-16 01:00:09

标签: ruby-on-rails ruby rspec rubygems nokogiri

我正在研究Michael Hartl的RoR教程。我在第3章。不幸的是,复制和粘贴宝石文件对我来说不起作用,但我想出了哪个宝石是问题所在。它是水豚宝石。我已经评论过并继续教程,但我还需要使用宝石。

以下是一个示例$ bundle update给出错误:

$ bundle update
Fetching gem metadata from https://rubygems.org/.........

(Removed a bunch of text)

Building nokogiri using system libraries.

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    /Users/dbz/.rvm/rubies/ruby-2.0.0-p481/bin/ruby extconf.rb --use-system-libraries
Building nokogiri using system libraries.
libxml2 version 2.6.21 or later is required!
*** 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.

(Removed a bunch of text)


Gem files will remain installed in /Users/dbz/.rvm/gems/ruby-2.0.0-p481/gems/nokogiri-1.6.3.1 for inspection.
Results logged to /Users/dbz/.rvm/gems/ruby-2.0.0-p481/gems/nokogiri-1.6.3.1/ext/nokogiri/gem_make.out
An error occurred while installing nokogiri (1.6.3.1), and Bundler cannot
continue.
Make sure that `gem install nokogiri -v '1.6.3.1'` succeeds before bundling.

我尝试去nokogiri网站并修复问题,但是当我尝试更新丢失的库(错误的早期部分)时,我的机器说我已经有了它们。

这是我的Gemfile:

source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=railstutorial_rails_4_0

gem 'rails', '4.0.8'

group :development, :test do
  gem 'sqlite3', '1.3.8'
  gem 'rspec-rails', '2.13.1'
end

group :test do
  gem 'selenium-webdriver', '2.35.1'
  #gem 'capybara', '2.1.0'   # This line breaks everything
end

gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'

group :doc do
  gem 'sdoc', '0.3.20', require: false
end

group :production do
  gem 'pg', '0.15.1'
  gem 'rails_12factor', '0.0.2'
end

编辑:从http://nokogiri.org/tutorials/installing_nokogiri.html安装页面

我遵循了所有步骤,并且在最后一步我需要运行命令

gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.7.8/include/libxml2 
                    --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.8/lib 
                    --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26 
                    --with-iconv-include=/usr/local/Cellar/libiconv/1.13.1/include 
                    --with-iconv-lib=/usr/local/Cellar/libiconv/1.13.1/lib

我的控制台的输出是:

Daniels-MacBook-Air:libiconv-1.13.1 dbz$ pwd
/Users/dbz/libiconv-1.13.1
Daniels-MacBook-Air:libiconv-1.13.1 dbz$ gem install nokogiri -- --with-xml2-    include=/usr/local/Cellar/libxml2/2.7.8/include/libxml2 
                    --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.8/lib 
                    --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26 
                    --with-iconv-include=/usr/local/Cellar/libiconv/1.13.1/include 
                    --with-iconv-lib=/usr/local/Cellar/libiconv/1.13.1/lib
Building native extensions with: '--with-xml2-    include=/usr/local/Cellar/libxml2/2.7.8/include/libxml2'
This could take a while...
Building nokogiri using packaged libraries.
ERROR:  Error installing nokogiri:
    ERROR: Failed to build gem native extension.

    /Users/dbz/.rvm/rubies/ruby-2.0.0-p481/bin/ruby extconf.rb --with-xml2-    include=/usr/local/Cellar/libxml2/2.7.8/include/libxml2
Building nokogiri using packaged libraries.
-----
libiconv is missing.  please visit     http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.
-----
*** 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
    --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/dbz/.rvm/rubies/ruby-2.0.0-p481/bin/ruby
    --help
    --clean
    --use-system-libraries
    --enable-static
    --disable-static
    --with-zlib-dir
    --without-zlib-dir
    --with-zlib-include
    --without-zlib-include=${zlib-dir}/include
    --with-zlib-lib
    --without-zlib-lib=${zlib-dir}/lib
    --enable-cross-build
    --disable-cross-build


Gem files will remain installed in /Users/dbz/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/nokogiri-1.6.3.1 for inspection.
Results logged to /Users/dbz/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/nokogiri-1.6.3.1/ext/nokogiri/gem_make.out
Daniels-MacBook-Air:libiconv-1.13.1 dbz$                         --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.8/lib 
-bash: --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.8/lib: No such file or directory
Daniels-MacBook-Air:libiconv-1.13.1 dbz$                         --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26 
-bash: --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26: No such file or directory
Daniels-MacBook-Air:libiconv-1.13.1 dbz$                         --with-iconv-include=/usr/local/Cellar/libiconv/1.13.1/include 
-bash: --with-iconv-include=/usr/local/Cellar/libiconv/1.13.1/include: No such file or directory
Daniels-MacBook-Air:libiconv-1.13.1 dbz$                         --with-iconv-lib=/usr/local/Cellar/libiconv/1.13.1/lib
-bash: --with-iconv-lib=/usr/local/Cellar/libiconv/1.13.1/lib: No such file or directory

4 个答案:

答案 0 :(得分:2)

您可能遗漏了一些包裹。尝试手动安装

对于Mac OSX:

$ sudo port install libxml2 libxslt

使用homebrew

$ brew install libxml2

在此处查看此LINK以获取更多信息。古德勒克!

答案 1 :(得分:2)

我找到了一个有效的解决方案:

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

来自:Nokogiri 'Failed to build gem native extension' when I run bundle install

来源来源:https://github.com/sparklemotion/nokogiri/issues/1099#issuecomment-43023208

答案 2 :(得分:1)

只需在控制台中键入此内容:gem install nokogiri -v '1.6.3.1'然后按Enter键...完成后...运行bundle

如果您使用的是自制..输入brew update,请输入brew doctor

答案 3 :(得分:0)

在看到你的帖子后,我刚解决了同样的问题。这是Homebrew的问题,不包括版本9.0及更高版本的libicov。您需要手动安装库,然后使用定义的lib路径进行安装。见http://nokogiri.org/tutorials/installing_nokogiri.html