我安装了新的稳定的Ruby版本,当我开始安装gem时,我发现在成功安装gem之后,它们的路径没有添加到Ruby加载路径中。
这个问题的原因是什么?我怎样才能实现它?
感谢。
这是我的环境:
$ lsb_release -d
Description: Debian GNU/Linux 5.0.6 (lenny)
$ cat ~/.gemrc
gem: --no-ri --no-rdoc gemhome: /home/<username>/.gem gempath: - /home/<username>/.gem
$ gem environment
RubyGems Environment: - RUBYGEMS VERSION: 1.3.7 - RUBY VERSION: 1.9.2 (2010-08-18 patchlevel 0) [i686-linux] - INSTALLATION DIRECTORY: /home/<username>/.gem - RUBY EXECUTABLE: /usr/local/bin/ruby - EXECUTABLE DIRECTORY: /home/<username>/.gem/bin - RUBYGEMS PLATFORMS: - ruby - x86-linux - GEM PATHS: - /home/<username>/.gem - GEM CONFIGURATION: - :update_sources => true - :verbose => true - :benchmark => false - :backtrace => false - :bulk_threshold => 1000 - "gem" => "--no-ri --no-rdoc" - "gemhome" => "/home/<username>/.gem" - "gempath" => ["/home/<username>/.gem"] - REMOTE SOURCES: - http://rubygems.org/
$ gem list
*** LOCAL GEMS *** rack (1.2.1) sqlite3-ruby (1.3.1)
$ ruby -e "puts $:"
# There's neither /home/<username>/.gem/gems/rack-1.2.1/lib # nor home/<username>/.gem/gems/sqlite3-ruby-1.3.1/lib here. /usr/local/lib/ruby/site_ruby/1.9.1 /usr/local/lib/ruby/site_ruby/1.9.1/i686-linux /usr/local/lib/ruby/site_ruby /usr/local/lib/ruby/vendor_ruby/1.9.1 /usr/local/lib/ruby/vendor_ruby/1.9.1/i686-linux /usr/local/lib/ruby/vendor_ruby /usr/local/lib/ruby/1.9.1 /usr/local/lib/ruby/1.9.1/i686-linux
更新
我不能要求任何已安装的宝石,因为它们不在$:。
中$ ruby -e "require 'rack'; puts $:"
:29:in `require': no such file to load -- rack (LoadError) from :29:in `require' from -e:1:in `'
但是
$ ruby -e "$: << '/home/<username>/.gem/gems/rack-1.2.1/lib'; require 'rack'; puts $:"
/usr/local/lib/ruby/site_ruby/1.9.1 /usr/local/lib/ruby/site_ruby/1.9.1/i686-linux /usr/local/lib/ruby/site_ruby /usr/local/lib/ruby/vendor_ruby/1.9.1 /usr/local/lib/ruby/vendor_ruby/1.9.1/i686-linux /usr/local/lib/ruby/vendor_ruby /usr/local/lib/ruby/1.9.1 /usr/local/lib/ruby/1.9.1/i686-linux /home/<username>/.gem/gems/rack-1.2.1/lib # Here it is!
它只适用于这种方式:(
答案 0 :(得分:3)
您尚未加载任何宝石:
ruby -e '
puts "Before require: #{$:.grep /rack/}"
require "rack"
puts "After require: #{$:.grep /rack/}"
'
# Before require: []
# After require: ["C:/Ruby/YARV/1.9.2/lib/ruby/gems/1.9.1/gems/rack-1.2.1/bin",
# "C:/Ruby/YARV/1.9.2/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib"]
ruby -e '
puts "Before gem: #{$:.grep /rack/}"
gem "rack"
puts "After gem: #{$:.grep /rack/}"
require "rack"
puts "After require: #{$:.grep /rack/}"
'
# Before gem: []
# After gem: ["C:/Ruby/YARV/1.9.2/lib/ruby/gems/1.9.1/gems/rack-1.2.1/bin",
# "C:/Ruby/YARV/1.9.2/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib"]
# After require: ["C:/Ruby/YARV/1.9.2/lib/ruby/gems/1.9.1/gems/rack-1.2.1/bin",
# "C:/Ruby/YARV/1.9.2/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib"]
答案 1 :(得分:0)
1.9.2
的情况发生了变化http://wiki.github.com/rdp/ruby_tutorials_core/ruby-talk-faq#gem_loading_fails_191
它现在基本上为你自动加载rubygems,而不是预先填充加载路径。