Here are my local gems :
$ gem list
*** LOCAL GEMS ***
actionmailer (4.0.0, 3.2.14)
actionpack (4.0.0, 3.2.14)
activemodel (4.0.0, 3.2.14)
activerecord (4.0.0, 3.2.14)
activerecord-deprecated_finders (1.0.3)
activeresource (3.2.14)
activesupport (4.0.0, 3.2.14)
arel (4.0.0, 3.0.2)
atomic (1.1.13)
builder (3.1.4, 3.0.4)
bundler (1.3.5)
bundler-unload (1.0.1)
erubis (2.7.0)
hike (1.2.3)
i18n (0.6.5)
journey (1.0.4)
json (1.8.0)
mail (2.5.4)
mime-types (1.24)
minitest (4.7.5)
multi_json (1.7.9)
polyglot (0.3.3)
rack (1.5.2, 1.4.5)
rack-cache (1.2)
rack-ssl (1.3.3)
rack-test (0.6.2)
rails (3.2.14)
railties (4.0.0, 3.2.14)
rake (10.1.0)
rdoc (3.12.2)
rubygems-bundler (1.2.2)
rubygems-update (2.0.7)
rvm (1.11.3.8)
sprockets (2.10.0, 2.2.2)
sprockets-rails (2.0.0)
thor (0.18.1)
thread_safe (0.1.2)
tilt (1.4.1)
treetop (1.4.15)
tzinfo (0.3.37)
But when I type rails -v
I get this :
$ rails -v
Rails 4.0.0
$ which rails
/Users/polonium/.rvm/rubies/ruby-2.0.0-p247/bin/rails
How can I specify rvm to use rails version 3.2.14 ?
Thanks in advance
You can create a new rails app with a particular rails version, like this
rails _3.2.14_ new myApp
How can I specify rvm to use rails version 3.2.14 ?
rvm has nothing to do with rails. rvm is used to manage multiple ruby installations. And each of your ruby installations can be associated with multiple gemsets. For instance, say you have ruby 1.9.3 installed and you created two gemsets for ruby 1.9.3: gemsetA and gemsetB. If you tell rvm to use ruby 1.9.3 with gemsetA, that means:
Your ruby programs will be executed by ruby 1.9.3.
Your ruby programs can require any gem in gemsetA (which then allows your program to use the methods (or classes) defined in gemsetA), but any gems in gemsetB cannot be seen by your ruby program.
Here's a concrete example:
~$ rvm list
rvm rubies
ruby-1.8.7-p370 [ i686 ]
* ruby-1.9.3-p194 [ x86_64 ]
=> ruby-2.0.0-p0 [ x86_64 ]
ruby-2.0.0-p247 [ x86_64 ]
# => - current
# =* - current && default
# * - default
~$ rvm use 1.9.3-p194
Using /Users/7stud/.rvm/gems/ruby-1.9.3-p194
.
~$ rvm gemset list (This lists only the gemsets for the current ruby version)
gemsets for ruby-1.9.3-p194 (found in /Users/7stud/.rvm/gems/ruby-1.9.3-p194)
=> (default)
global
programming
rails3tutorial
rails4
~$ rvm gemset use programming
Using ruby-1.9.3-p194 with gemset programming
After I do that, my ruby programs will be executed by ruby 1.9.3 and any gems in the programming gemset can be required into my ruby program. You can use a shortcut to perform both those commands in one step:
rvm use ruby 1.9.3-p194@programming
You just combine the ruby version and the gemset with an '@' between them.
But when I type rails -v I get this :
$ rails -v
Rails 4.0.0
That's because the current gemset contains the gem for rails 4.0.0. If you want to see $ rails -v
output Rails 3.2.14
, then you need to tell rvm to switch to a gemset that contains the rails 3.2.14 gem.
However, you can make rvm automatically switch to the proper rails version and gemset for your rails project. In your Gemfile, add a comment after the ruby version:
ruby '2.0.0'
#ruby-gemset=railstutorial4_gems
Then whenever you switch to the directory containing your rails project, rvm will automatically switch the current ruby to ruby 2.0.0 and the current gemset to railstutorial4_gems. If you change directories out of your rails app, rvm will change the current ruby and the current gemset back to what they were.
I'm just a rails beginner, but here are the steps I use to create a new project, which are straight out of the railstutorial book (http://ruby.railstutorial.org/ruby-on-rails-tutorial-book)
1)
.../rails_projects$ rvm use <ruby version here>@<new gemset name here> --create
e.g.
.../rails_projects$ rvm use ruby-1.9.3-p194@myapp_gemset --create
2)
.../rails_projects$ gem install rails --version 3.2.14
Because the current gemset is the myapp gemset, that command installs the rails 3.2.14 gem into the myapp gemset.
3)
.../rails_projects$ rails new myapp
.../rails_projects$ cd myapp
The current gemset is still myapp_gemset.
4)
.../rails_projects/myapp$ rails -v
Rails 3.2.14
In case anyone was wondering what the heck the following two gemsets are all about:
gemsets for ruby-1.9.3-p194 (found in /Users/7stud/.rvm/gems/ruby-1.9.3-p194)
=> (default)
global
rvm creates those two gemsets for every ruby version you install. After you install a ruby version, if you don't create a gemset yourself for that ruby version, and you install a gem, then the gem goes into the (default) gemset. And, if you want all your gemsets to contain a certain gem, you can switch to the global gemset and install the gem there.
Update: -------
To maintain compatibility with other ruby version managers, you can specify the ruby version and gemset name for your project in a different file rather than in the Gemfile:
$ cd ~/rails_projects/myapp
~/rails_projects/myapp$ echo 2.0.0 > .ruby-version
~/rails_projects/myapp$ echo myapp_gemset > .ruby-gemset
You'll still get the same automatic ruby version and gemset switching when you cd
into your project's directory. See the rvm docs here.
the path you found /Users/polonium/.rvm/rubies/ruby-2.0.0-p247/bin/rails
is not proper path you would found in standard rvm installation while doing proper use of rvm, what you would see should be: /Users/polonium/.rvm/gems/ruby-2.0.0-p247/bin/rails
to get it working properly try this flow:
rvm use 2.0.0
rvm gemset empty
rvm use @rails3 --create
gem install rails -v "~>3.2"
rvm use @rails4 --create
gem install rails -v "~>4"
this way now you can switch between this two rails installations with:
rvm use 2.0.0@rails3
rails -v # rails 3.2...
rvm use 2.0.0@rails4
rails -v # rails 4.0...
you should do: gem install 'rails' -v '3.2.13'
You should use a clean gemset, if you are using rvm, you can try:
rvm gemset create
rvm gemset use
Now you have a clean gemset, it's time to install rails,
gem install rails -v '3.2.13'
and then create a rails app,
rails new app_name
"railties (4.0.0," is the problem you have. I guess it was installed by mistake?
Uninstall that version using, gem uninstall railties, and then picking the option with 4.0.0.
Now the command "rails -v" will return your expected version which is "3.2.14"
Make sure to check the global gemset by first making sure you are in the ruby version you intend to use
$ruby -v
Then switch to the global gemset (the global gemset applys to all of the gemsets so be sure to keep it clean and universal...or global, hence the name)
$rvm gemset use global
After that check the gem list for gems that can affect it like the "railties" gem that Harsha mentioned by typing
$gem list
Sometimes the global gemset can be populated by an accidental gem that will affect all other gemsets. If you find a misplaced gem you can uninstall it simply with
$gem uninstall examplegem
or for a specific version of that gem pass in the -v with the version in quotes
$gem uninstall examplegem -v"3.2.1"
And read 7stud's comment on creating and using RVM for changing between different gemsets.