Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
572 views
in Technique[技术] by (71.8m points)

ruby - How to switch to an older version of rails

I'm trying to follow an older book written in 2011.

So, randomly picked 3.1.3 version since that's Nov 2011.

How do I switch to that version in my RVM?

Currently have Rails 4.0.0.beta1 version ...

Please don't suggest to put it in the Gemfile because there are a lot of other dependencies that will just be too troublesome to deal with, hence if I just switch, I'm assuming it means that other dependencies will be taken care of at the same time too, right?

UPDATE

**-s-MacBook-Pro:agile **$ rails -v
Rails 4.0.0.beta1
**-s-MacBook-Pro:agile **$ gem install rails -v 3.1.3
Successfully installed rails-3.1.3
1 gem installed
**-s-MacBook-Pro:agile **$ rvm gemset create rails 313
gemset created rails    => /Users/**/.rvm/gems/ruby-1.9.3-p392@rails
gemset created 313  => /Users/**/.rvm/gems/ruby-1.9.3-p392@313
**-s-MacBook-Pro:agile **$ ruby -v
ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-darwin10.8.0]
**-s-MacBook-Pro:agile **$ rvm 1.9.3p392-head@rails313
Unknown ruby interpreter version: '1.9.3p392'.
**-s-MacBook-Pro:agile **$ 

UPDATE AGAIN

**-s-MacBook-Pro:agile **$ rvm gemset use 313
Using ruby-1.9.3-p392 with gemset 313
**-s-MacBook-Pro:agile **$ rails -v
/Library/Ruby/Site/1.8/rubygems/dependency.rb:296:in `to_specs': Could not find 'rails'     (>= 0) among 2 total gem(s) (Gem::LoadError)
from /Library/Ruby/Site/1.8/rubygems/dependency.rb:307:in `to_spec'
from /Library/Ruby/Site/1.8/rubygems/core_ext/kernel_gem.rb:47:in `gem'
from /usr/bin/rails:18
**-s-MacBook-Pro:agile **$ 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...