Ruby on Rails - Error making new app (rb:55:in 

2020-04-21 06:22发布

问题:

I've been following Mike Hartl's excellent Ruby on Rails Tutorial`.

I had to make some decisions earlier about versions for gem files and ruby. I decided (after some problems getting Heroku to work that I'd directly mimic the tutorial and versions of ruby described - leading me to go with rvm use 2.0.0 to set my version of ruby.

All was great on chapter one but now I'm getting an error message when i try to create a new rails project:

$ rails new demo_app

/home/huw/.rvm/rubies/ruby-2.0.0-p481/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in require': cannot load such file -- rails/cli (LoadError) from /home/huw/.rvm/rubies/ruby-2.0.0-p481/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:inrequire' from /usr/bin/rails:9:in `'

I have no idea what that means... but as its referencing my ruby version I'm guessing that my rails and ruby versions are out of sync...

Could someone advise on possible courses of action?

I imagine possible options would be:

  1. Reset my ruby version to the latest (but I don't know what clashes that would create with gems!)
  2. Downgrade from rails 4.1 to rails 4 (I believe that's Mike Hardl's version)
  3. Force things through somehow

I'm a complete rails Noob however, and have no idea where to begin on any of those options - or if that error code even backs up my assumptions!

回答1:

Forgive the "answer" but I don't have the rep to post a mere comment :-(

Have you tried looking at the RVM site? It has a troubleshooting page that may help you.

If not, have you tried get rvm stable and then typing in the rails new app_name command?

Other useful RVM commands are rvm list rubies and rvm gemset list. It may be the case that the ruby version you're using doesn't have rails for some reason.



回答2:

As per zwippie's answer in the comment section, the solution was achieved as follows.

rails -v produced a very similar looking output to the error message above.

gem install rails after hanging for a second installed rails successfully. I am now able to add a new project.

I'm unsure why this has happened as I've been successfully making new rails projects both on this laptop and in this directory for the last two weeks, even up until this morning. However as zwippie notes perhaps this is an RVM setup issue. I'll go away and read up but if anyone had any additional pointers from documentation that might shed light on the issue I'm appreciate any links in the comment.

Many thanks all.



回答3:

check for the rails is installed on your machine by the command bundle show rails.

If you get the version of rails and are still getting the above error, to resolve it you may have to use the command bundle exec before every rails command as in bundle exec rails s.