找不到ubuntu ruby​​ gem

时间:2012-09-25 11:43:25

标签: ruby rubygems install ubuntu-12.04

我想在Ubuntu Precise中使用rbgccxml。这个宝石需要nokogiri。因此,我首先安装了ruby-nokogiri(v1.5.0)Ubuntu软件包。然后我尝试通过'gem install'安装rbgccxml但它总是试图安装nokogiri(> 1.4)。为了防止这种情况,我使用了'gem install --ignore-dependencies rbgccxml'。

$ gem which rbgccxml
/var/lib/gems/1.8/gems/rbgccxml-1.0.3/lib/rbgccxml.rb
$ gem which nokogiri
/usr/lib/ruby/vendor_ruby/nokogiri.rb

现在我的行​​为很奇怪。以下脚本:

require 'nokogiri'
puts 'step 1'
require 'rubygems'
puts 'step 2'
require 'rbgccxml'
puts 'step 3'

输出:

step 1
step 2
/usr/lib/ruby/vendor_ruby/1.8/rubygems/dependency.rb:247:in `to_specs': Could not find nokogiri (~> 1.4.0) amongst [rbgccxml-1.0.3] (Gem::LoadError)
from /usr/lib/ruby/vendor_ruby/1.8/rubygems/specification.rb:771:in `activate_dependencies'
from /usr/lib/ruby/vendor_ruby/1.8/rubygems/specification.rb:760:in `each'
from /usr/lib/ruby/vendor_ruby/1.8/rubygems/specification.rb:760:in `activate_dependencies'
from /usr/lib/ruby/vendor_ruby/1.8/rubygems/specification.rb:744:in `activate'
from /usr/lib/ruby/vendor_ruby/1.8/rubygems.rb:209:in `try_activate'
from /usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:58:in `require'
from test3.rb:8

那么,为什么nokogiri是通过require而不是在rbgccxml中找到的?

1 个答案:

答案 0 :(得分:1)

rbgccxml使用pessimistic version constraint指定对nokogiri的依赖关系,如下所示:

gem "nokogiri", "~>1.4.0"

这相当于:

gem "nokogiri", ">= 1.4.0", "< 1.5.0"

这意味着rbgccxml需要在您安装的版本之前使用nokogiri版本。

如果您不特别需要nokogiri 1.5.0,那么让rubygems解析并为您安装依赖项。