Rubygems. A newly installed gem isn't added to $LOAD

I installed the new stable Ruby release and when I began to install gems I found out that the paths to them isn't added to the Ruby load path after successful installation of the gems.

What is the reason of this issue? How can I achieve it?

Thanks.

Here's my environment:

$ 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

Updated


I can't require any of the installed gems because they arn't in $:.

$ ruby -e "require 'rack'; puts $:"
:29:in `require': no such file to load -- rack (LoadError)
        from :29:in `require'
        from -e:1:in `'

But.

$ 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!

It works that way only : (


您尚未加载任何宝石:

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"]

things have changed for 1.9.2

http://wiki.github.com/rdp/ruby_tutorials_core/ruby-talk-faq#gem_loading_fails_191

it basically auto loads rubygems for you now, instead of pre-populating the load path.

链接地址: http://www.djcxy.com/p/25270.html

上一篇: RubyGems的。 LoadError在Rails中

下一篇: RubyGems的。 新安装的gem不会添加到$ LOAD