我正在尝试将`rack / test`加载到我的应用程序中,但由于某种原因它无法运行。当我这样做时:
gem list rack-test
我得到了
rack-test (0.6.2)
所以它已安装。
我也可以通过以下方式获得路径:
gem which rack/test
是
/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
但是
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"'
产量
["/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>'
我做错了什么?
答案 0 :(得分:0)
这可能是gem文件的权限问题。如果我使rack/test.rb
文件不可读,我可以重现你所看到的内容:
$ 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>'
换句话说,如果文件存在但由于某种原因无法读取,那么gem which
将显示该文件,但在Ruby中尝试require
意味着读取它,所以这将是提出LoadError
。
使用
检查权限$ ls -l `gem which rack/test`
它们应该看起来像-rw-r--r--
。如果他们不这样做,这可能是你的问题。简单的解决方法是使用chmod
来更正权限,但您也需要查看其他文件,并尝试确定权限错误的原因。
答案 1 :(得分:0)
通过重新安装rvm来解决。由于某种原因,有一个多余的ruby可执行文件,它搞砸了。