How to Switch to an Older Version of Rails

How to switch to an older version of rails

First, uninstall the version of Rails you have:

gem uninstall rails

Next, install the version of Rails you want, like so:

gem install rails -v 3.1.12

There are a few ways to have both "installed" at the same time. As Joe Frambach suggested, you could install Rails 4 in a VM. You could also install RVM - the Ruby enVironment Manager - and use separate gemsets to keep the two versions of Rails apart. But if you are just learning you may not want to bother with this.

Edit: @Shadwell's answer got it right, although it could use some expansion, which I'll do here:

> rvm gemset create rails3
> rvm gemset use rails3
> gem install rails -v 3.1.12
> rails my_new_app

How do I switch to older versions of the ruby/rails environment?

Try,

rvm use <ruby version>
rvm gemset create rails2.3.2
rvm <ruby version>@rails2.3.2
gem install rails --version=2.3.2

Finally the syntax to create a new rails app in older versions of rails was just:

rails <appanme>

For more information about gemsets:
RVM: Named Gem Sets

RVM switching Rails Versions

That's not a problem with RVM and Rails. Using the Gemfile is the best way to do this, IMHO! In your Gemfile, you can specify which ruby and which gemset within that ruby to use.

Set Default Ruby/Gemset --for system

First, lets establish that default ruby for the system on 5.0.0. This will allow any new/existing Rails projects to default to this ruby version (except for those projects that override with the Gemfile):

rvm use --default 5.0.0

..and of course, if you want it fixed to a specified gemset:

rvm use --default 5.0.0@my_default_gemset

Set Default Ruby/Gemset --for Rails specific App on Gemfile

Example 1

If you want to setup your rails app to utilize the RVM gemset 2.2.1@rails_2_1_1, similar to the RVM command below...

rvm use 2.2.1@rails_2_1_1

In your Gemfile, specify right below the source line the following two commented lines:

source 'https://rubygems.org'
#ruby=2.2.1
#ruby-gemset=rails_2_1_1

Now, when you cd into your rails' app directory, you should receive the following message, or similiar:

RVM used your Gemfile for selecting Ruby, it is all fine - Heroku does 
that too, you can ignore these warnings with 'rvm rvmrc warning ignore
/my/rails/app/path/Gemfile'.

To ignore the warning for all files run 'rvm rvmrc warning ignore
allGemfiles'.

You can double check your results:

rvm list gemsets

ruby-2.2.1 [ x86_64 ]
ruby-2.2.1@global [ x86_64 ]
=> ruby-2.2.1@rails_2_1_1 [ x86_64 ]
ruby-5.0.0 [ x86_64 ]
ruby-5.0.0@global [ x86_64 ]

Example 2

Another example using ruby-2.0.0-p247@rails-4.0.0, example RVM command...

rvm use ruby-2.0.0-p247@rails-4.0.0

In your Gemfile, specify:

#ruby=2.0.0-p247
#ruby-gemset=rails-4.0.0

How to use lower version of rails

You can use rvm for different rails applications.

Try this link https://rvm.io/rvm/install.

After installing rvm. in your gem file you can mention your rails version. it will install automatically.

gem 'rails', '~> 2.3.3'

Change rails version used by rvm

You can create a new rails app with a particular rails version, like this:

rails _3.2.14_ new myApp

How to switch back to Rails 5 once the version has been changed?

You can uninstall Rails, and re-install it, and reinstalling it will convert the version to the latest.

gem uninstall rails
gem install rails # To re-install it.

Edit:

If you do not want to uninstall Rails, you may need to create a new Gemset for using using Rails 5 throughout your project space. Here's how:

rvm gemset create rails-5.0.0
rvm use 2.2.2@rails-5.0.0 --default

Kindly replace 2.2.2 with the Ruby version that you would like to use, but it should be later than 2.2.2.

Terminal still shows older version of rails even after updating

This is because there are now two versions of rails in your railties.
Try to run this first:

gem uninstall railties

By running this command your screen will show rails gems list like the following:

Select gem to uninstall:
1. railties-3.2.18
2. railties-4.2.6
3. All versions
>

Type 3 to remove all. now your gem list has no rails gem. Now you can install rails -v 3.2.3. After installation, rails -v will show: Rails 3.2.3



Related Topics



Leave a reply



Submit