Cannot load files using require

可紊 提交于 2020-01-23 12:05:48

问题


I just downloaded Ruby 2.0 and have a serious problem with require when I try to run a simple Sinatra app:

/Users/Kuba/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- sinatra (LoadError)
from /Users/Kuba/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from test.rb:1:in `<main>'

Also, this and other programs I have a problem with now, worked perfectly fine when i was using Ruby 1.8.7.

What should I do?


回答1:


I had this problem today too when upgrading to >= 1.9, I was given this article to read: "Upgrading From REE 1.8.7 to Ruby 1.9.3"

The relevant portion of your question, as mentioned in your comment:

but programs in which i dont use any gems, but just other files made by myself, gives me the same result

From the article1

Load Paths:

In Ruby 1.9.3, LOAD_PATH no longer includes “.” because it was deemed a security risk. You can explicitly add it when requiring files, use absolute paths, or use require_relative.




回答2:


Did you also install the gems?

Ruby 2.0 is a complete new installation. Installing ruby 2.0 does not mean you keep the installed gems.

This is not Ruby 2.0 specific. As far as I know each new ruby installation has its own gems.

There are tools to administrate diffferent rubies:

  • rvm (ruby version manager)
  • pik for windows



回答3:


Probably the libraries you were using are located under the directory for Ruby 1.8. I think it is a good idea to freshly reinstall the required libraries under Ruby 2.0.



来源:https://stackoverflow.com/questions/15179605/cannot-load-files-using-require

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!