How to switch to an older version of rails

I accidentally installed rails version 4.1.7 but I need rails version 4.1.6 . In order to fix this issue I uninstalled rails with this command:

gem uninstall rails

and install version 4.1.6 with:

gem install rails -v 4.1.6

but when I run rails -v it's version still be 4.1.7.

By running gem list I see that railties (4.1.7, 4.1.6) package exist in my gems. I removed it with below procedure and fix rails version problem.

$ gem uninstall railties

Select gem to uninstall:
 1. railties-4.1.6
 2. railties-4.1.7
 3. All versions
>

Input 2 and uninstall version 4.1.7.


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

You're already using RVM it seems. Create a gemset for the different rails versions:

> rvm gemset create rails3
> rvm gemset use rails3
> bundle install

You'll then only get the gems installed in that gemset. I'd be tempted to create a gemset for rails4 too rather than having gems kicking around that aren't in a gemset. Then to switch between them you just rvm gemset use whichever one you want to.

There's more about gemset here and it'd be worth reading up on rvmrc too because then you don't even have to switch gemsets.


We can change our default version of rails.
Rails version defined in Ruby "bin" itself.

install required rails version by

gem install rails -v 4.2.6

and

In Windows:

  • goto your current ruby version 'bin' folder ( in my system c:/RubyXX-x64/bin)
  • you will find "rails" file there
  • open that "rails" file with text editor you will see ----- version = ">= 0" (which means: it opens the highest version of rails, which exist in your ruby gems)
  • replace it with specific rails version as ----- version = "4.2.6"

In Linux:

  • goto ruby lib folder (in my system ---/.rvm/gems/ruby-2.3.1/bin)

$ which bundle

(gives path to find from which ruby your bundler executing( ---/.rvm/gems/ruby-2.3.1/bin/bundler) )

  • edit "rails" file with your text editor

dathu@ubuntu:~/.rvm/gems/ruby-2.3.1/bin$ sudo subl rails

  • replace ( verion = ">= 0" ) with ( verion = "4.2.6" ) your specific installed version.

  • save and check your current rails version.