Rails command line not found when installed with R

2019-06-17 01:25发布

问题:

After installing RVM, I have installed Ruby 1.8.7 then Rails 3. When I do which rails I get /Users/davidbenhamou/.rvm/gems/ruby-1.8.7-p302/bin/rails. But when I do rails -v I get -bash: /usr/bin/rails: No such file or directory

Why is Rails not working? Note: I have followed all steps from RVM website and Ruby command line work fine (ruby -v).

回答1:

To see the rubies you have installed:

rvm list rubies

And you'll see something like this:

   ree-1.8.7-2011.03 [ i686 ]
*  ruby-1.9.2-p290 [ x86_64 ]
   ruby-1.9.3-p0 [ x86_64  ] 
=> ruby-1.9.3-p125 [ x86_64 ]
   ruby-1.9.3-p125-perf [ x86_64 ]

To use a specific one:

rvm use ruby-1.9.3-p125

then if you do ruby --version, you'll see:

ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin10.7.0]

In each of these rubies you need to install all the gems you want to use. The way I do it is actually by using Bundler to install all the gems for a project. But for the simple case here, just do:

rvm all do gem install rails

This will install the rails gem in all your ruby versions. To install to a particular one, use:

rvm ruby-1.9.3-p125  do gem install rails


回答2:

after you installed RVM and after you set the default Ruby version in RVM, you need to re-install all ruby gems, e.g.

gem install rails

you need to install those gems as the user, not as root.

Because from now on RVM will keep track of all installed gems by the ruby version which was used to install them!