13

I have rails version 3.2.1 in my machine. The other versions installed are 3.0, 3.0.3. Whenever i run

 rails new PROJECT_NAME

command ,the project gets created in version 3.2.1. I want to create the project in version 3.0.3.

What should i do?

lucapette
  • 20,564
  • 6
  • 65
  • 59
imran
  • 626
  • 2
  • 13
  • 24
  • possible duplicate of [Specifying rails version to use when creating a new application](http://stackoverflow.com/questions/379141/specifying-rails-version-to-use-when-creating-a-new-application) – lucapette Feb 28 '12 at 09:42
  • The question is for Rails 2.x but the answer still works form Rails 3.X. – lucapette Feb 28 '12 at 09:42

3 Answers3

31

you can create new app with older version

rails _3.0.3_ new appname 

but you may get error as

/usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:316:inbin_path': can't find gem railties (["3.0.3"]) with executable rails (Gem::GemNotFoundException) from /usr/local/bin/rails:19:in'

so

again install rails gem

sudo gem install rails -v="3.0.3"

now you can do

rails _3.0.3_ new app

it will work fine

thank you

devudilip
  • 1,270
  • 14
  • 25
  • I think that `sudo gem install rails -v="3.0.3"` should be `sudo gem install rails -v "3.0.3"` – Tass Feb 27 '13 at 17:14
  • Hi Tass, we can use both. Both will work, i just tried out and its worked. – devudilip Feb 28 '13 at 06:51
  • Weird. I tried that first syntax yesterday and it didn't work for me. >.< Perhaps I should look into it again and see what kind of errors (if any) I receive. – Tass Feb 28 '13 at 14:09
  • Best thing is use RVM and install gems without sudo. – devudilip Mar 01 '13 at 07:11
  • I completely agree, but this is a production FreeBSD server which doesn't have RVM set up. In development I do use RVM. – Tass Mar 01 '13 at 14:13
  • can I somehow setup an app with the latest version of a major version, i.e. something like `rails _6_ new appname` but that resolves to 6.1.5 rather than 6.0.0? – xeruf Apr 11 '22 at 07:37
12

You could use something like RVM and install the other rails versions in a different gemset. Then select the gemset with an older rails version and your rails command should be from the older version.

Alternatively you should be able to use

rails _VERSION_ new myapp
Bernd May
  • 306
  • 1
  • 6
3

Suggest using bundler. Your project will have a Gemfile in which you specify the rails version you want:

gem "rails", "~> 3.0.3"

Once you have installed the bundler gem, bundle install will install the version of Rails you have specified.

Then, when you are ready to upgrade your version of Rails, you do this by specifying the version number you want to move to. Of course, this approach helps manage all of the gems that your project depends on, including the ones you only want in test and dev etc.

See http://gembundler.com/ for more.

novemberkilo
  • 661
  • 5
  • 15