我想在 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
那么,为什么在 rbgccxml 中通过 require 而不是通过 require 找到 nokogiri?