views:

69

answers:

1

I'm a bit confused about how paths work with gems. Here's the core of my confusion:

>> require 'rubygems'
=> false
>> Gem.available?('money')
=> true
>> require 'money'
LoadError: no such file to load -- money
        from (irb):3:in `require'
        from (irb):3
        from /usr/bin/irb:12:in `<main>'
>> Gem.available?('pony')
=> false
>> require 'pony'
=> true

This is being run by irb 0.9.5(05/04/13) This is especially confusing because gem list --local yields:

*** LOCAL GEMS ***

albino (1.0)
bcat (0.5.2)
builder (2.1.2)
bundler (1.0.0)
classifier (1.3.3)
diff-lcs (1.1.2)
directory_watcher (1.3.2)
fast-stemmer (1.0.0)
gdata (1.1.1)
gdata2 (0.1)
github-markup (0.5.0)
gollum (1.0.1)
google4r-checkout (1.0.6.1)
grit (2.2.0)
jekyll (0.7.0)
kwalify (0.7.1)
liquid (2.2.2)
maruku (0.6.0)
mime-types (1.16)
mocha (0.9.8)
money (3.0.5)
mustache (0.11.2)
nokogiri (1.4.3.1)
rack (1.2.1, 1.1.0)
rake (0.8.7)
rubygems-update (1.3.7)
sanitize (1.2.1)
sinatra (1.0)
syntax (1.0.0)
unicorn (1.1.3)

which notably contains money but not pony.

Here's the outputs of gem env:

RubyGems Environment:
  - RUBYGEMS VERSION: 1.3.7
  - RUBY VERSION: 1.9.1 (2010-01-10 patchlevel 378) [x86_64-linux]
  - INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.9.1
  - RUBY EXECUTABLE: /usr/bin/ruby1.9.1
  - EXECUTABLE DIRECTORY: /usr/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /usr/lib/ruby/gems/1.9.1
     - /home/aresnick/.gem/ruby/1.9.1
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/

And in case that doesn't make it clear, gem and ruby are using the same ruby, i.e.:

aresnick@dror:~$ which ruby
/usr/bin/ruby
aresnick@dror:~$ ls -al $(which ruby)
lrwxrwxrwx 1 root root 22 2010-08-28 20:08 /usr/bin/ruby -> /etc/alternatives/ruby
aresnick@dror:~$ ls -al /etc/alternatives/ruby
lrwxrwxrwx 1 root root 18 2010-08-28 20:08 /etc/alternatives/ruby -> /usr/bin/ruby1

I suspect the problem is with the paths that are being looked at, especially because of the other gems which I can and can't access, e.g. gdata is not available and sinatra is. . .

aresnick@dror:~$ gem which pony
/var/lib/gems/1.9.1/gems/pony-1.0/lib/pony.rb
aresnick@dror:~$ gem which money
/usr/lib/ruby/gems/1.9.1/gems/money-3.0.5/lib/money.rb
aresnick@dror:~$ gem which sinatra
/var/lib/gems/1.9.1/gems/sinatra-1.0/lib/sinatra.rb
aresnick@dror:~$ gem which gdata
/usr/lib/ruby/gems/1.9.1/gems/gdata-1.1.1/lib/gdata.rb
aresnick@dror:~$ irb
>> require 'sinatra'
=> true
>> require 'gdata'
LoadError: no such file to load -- gdata
    from (irb):2:in `require'
    from (irb):2
    from /usr/bin/irb:12:in `<main>'

So, I think that the /usr/lib/ruby/gems/1.9.1 gems are not being found and the /var ones are. I'm sure mucking around with symlinks could fix this, but I was wondering a) why this was happening and b) where are these paths are set and how can I set them?

A: 

I've had similar problems on a Debian system, which I'm guessing you're using or a system based off of since you're using alternatives, and the problem then was that I had installed rubygems through apt-get and then installed an updated version through source.

Messed things up good.

There is some kind of "religious" war between the Debian and rubygems team so it's just easier to installed rubygems from source on Debian.

I've no explanation for what is happening though. :(

ba
OK, switching back to Ruby 1.8.7 (the `apt-get` version) fixed everything. Thanks for the hint!
aresnick