1
votes

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 : (

2
This has nothing to do with your question. Gems only get added to the load path after they have been required. The fact that you can't require the gem has nothing to do with it not being in the load path, it has to do with your RubyGems installation being broken in some way.Jörg W Mittag
The load path is a place where the paths to the libraries are reside. When your install a gem a path to it is added the the load path automatically. That is $: is incremented by 1 line. And then you can require or load that gem. That was before I updated my Ruby installation. But now that doesn't work and I don't know the reason. My question was about that.Shamaoke

2 Answers

3
votes

You haven't loaded any gems yet:

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

things have changed for 1.9.2

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

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