18

I have installed two different rails versions in my system (Fedora).

gem list -d rails
*** LOCAL GEMS ***

rails (3.0.5, 1.2.1)
    Author: David Heinemeier Hansson
    Rubyforge: http://rubyforge.org/projects/rails
    Homepage: http://www.rubyonrails.org
    Installed at (3.0.5): /usr/local/lib/ruby/gems/1.8
                 (1.2.1): /usr/local/lib/ruby/gems/1.8

    Full-stack web application framework.

When i try to create the project like following way ("http://www.nomachetejuggling.com/2008/03/12/using-multiple-versions-of-rails/")

rails 1.2.1 myproject

But, it's not working. So, i checked

rails -v
Rails 3.0.5

So, can you help me, how to create the project with older version and newer version. Is there any way to set the particular rails version as default?

Mr. Black
  • 11,692
  • 13
  • 60
  • 85

8 Answers8

31

To use an older version than the latest you have installed, just wrap the version number in underscores:

rails _1.2.1_ myproject

matkins
  • 1,991
  • 1
  • 16
  • 22
  • 1
    I don't know if there's a way to set this as a system wide default. You could use a bash alias or similar, e.g. `alias rails="rails _1.2.1_"`. – matkins May 27 '11 at 06:04
  • thanks @matkins. Can you do one more favor for me. I have a one project in rails 1.2.1 version. now, i have additionally installed the new rails version, 3.0.0. So, when i try to run my project project (build by 1.2.1) script/server, it doesn't run. Is it right way to run when the two rails version installed in my system. the error is "127.0.0.1 - - [27/May/2011:11:05:21 IST] "GET / HTTP/1.1" 500 309" – Mr. Black May 27 '11 at 06:09
  • Can you give more details about the error? It might be worth asking another question about this as it seems to be a different issue. – matkins May 27 '11 at 11:11
5

I couldn't get matkins' answer to work via RailsInstaller on Windows 7, so I thought I'd post my solution for someone else to benefit from: (I don't have the reputation to offer this as a comment so I'm adding a new answer)

c:\>rails -v
Rails 4.0.0

c:\>rails _3.2.8_ app1 &REM This is going to bug out

Instead, I found this works:

c:\>rails _3.2.8_ new app1 &REM This will work
sameers
  • 4,855
  • 3
  • 35
  • 44
  • Yes.. Your answer is also correct.. But you were pointed rails 3 version and markins were pointed rails < *2 version.. Hopefully both will work. – Mr. Black Jul 25 '13 at 04:54
3

As @Shaun mentioned in this post, you can use multiple versions of Rails and Ruby in same time!
For using an specific version of ruby:

rvm use 1.9.3 --default

Switch --default is used for setting this version as Ruby default version.
For using an specific Rails and Ruby version:

rvm gemset create rails-3.2.3
rvm use 1.9.3@rails-3.2.3 --default
gem install rails

First line creates a gemset and related folder under /home/username/.rvm/gems/
Second line use that gemset as default one
Third line install specified version in gemset (Rails 3.2.3) on related folder.

This is my gems folder's contents:

cache  ruby-1.9.3-p194  ruby-1.9.3-p194@global  ruby-1.9.3-p194@rails-3.2.3

Initial folder is ruby-1.9.3-p194@global. Therefore for backing to previous state, just run:

rvm use 1.9.3@global

and you can see previous Rails and Ruby versions :)

Good luck

Community
  • 1
  • 1
S.M.Mousavi
  • 5,013
  • 7
  • 44
  • 59
3

The URL you posted solves your problem - you simply forgot the underscores.

varar:~ mr$ gem list rails

*** LOCAL GEMS ***

rails (3.1.0.rc1, 3.1.0.beta1, 3.0.3, 3.0.1)
varar:~ mr$ rails _3.0.1_ -v
Rails 3.0.1
fx_
  • 1,932
  • 13
  • 17
1

To create a project with the specific rails version use the below command: similar to matkins suggested

rails _5.0.7.2_ new <project_name>
Msvstl
  • 1,116
  • 5
  • 21
0

In your config/environment.rb file, place this at the beginning for the old version:

RAILS_GEM_VERSION = '1.2.1'

or this for the new version:

RAILS_GEM_VERSION = '3.0.5'

Chris Bunch
  • 87,773
  • 37
  • 126
  • 127
-1

here is a general format example. feel free to modify as needed

    rvm use ruby-2.1.0@rails4.2
Martin Tournoij
  • 26,737
  • 24
  • 105
  • 146
Sawo Cliff
  • 2,888
  • 1
  • 17
  • 21
-3

You first installed a rvm(rails version management) then type. rvm 1.2.1

User123
  • 566
  • 5
  • 16