Solved by reinstalling rvm. There was a superfluous ruby executable for some reason and it messed things up.
Question
I'm trying to load `rack/test` into my application, but it's not working for some reason. When I do:
gem list rack-test
I get
rack-test (0.6.2)
So it's installed.
I can also get the path with:
gem which rack/test
which is
/home/jacky/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-test-0.6.2/lib/rack/test.rb
But then
ruby -e 'puts $LOAD_PATH.inspect; $LOAD_PATH << "/home/jacky/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/gems/1.9.1/gems/"; require "rack/test"'
yields
["/home/jacky/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1", "/home/jacky/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/i686-linux", "/home/jacky/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby", "/home/jacky/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/vendor_ruby/1.9.1", "/home/jacky/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/vendor_ruby/1.9.1/i686-linux", "/home/jacky/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/vendor_ruby", "/home/jacky/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1", "/home/jacky/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/i686-linux"]
/home/jacky/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- rack/test (LoadError)
from /home/jacky/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from -e:1:in `<main>'
What am I doing wrong?
Solution 2
OTHER TIPS
This could be a permissions issue with the gem files. I can reproduce what you’re seeing if I make the rack/test.rb
file unreadable:
$ ls -l `gem which rack/test`
-rw-r--r-- 1 matt staff 9723 5 Nov 19:42 /Users/matt/.rvm/gems/ruby-1.9.3-p194/gems/rack-test-0.6.2/lib/rack/test.rb
$ ruby -e 'p require "rack/test"'
true
$ chmod a-r `gem which rack/test`
$ ls -l `gem which rack/test`
--w------- 1 matt staff 9723 5 Nov 19:42 /Users/matt/.rvm/gems/ruby-1.9.3-p194/gems/rack-test-0.6.2/lib/rack/test.rb
$ ruby -e 'p require "rack/test"'
/Users/matt/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `require': cannot load such file -- rack/test (LoadError)
from /Users/matt/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `rescue in require'
from /Users/matt/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
from -e:1:in `<main>'
In other words, if the file exists but isn’t readable for some reason, then gem which
will show the file, but trying to require
it in Ruby means reading it, and so this will raise a LoadError
.
Check the permissions with
$ ls -l `gem which rack/test`
They should look something like -rw-r--r--
. If they don’t, this could be your problem. The simple fix would be to use chmod
to correct the permissions, but you’ll want to look at the other files too, and try to determine why your permissions are wrong.