views:

54

answers:

4

On Ubuntu, if Rails 3.0 was installed using

sudo gem install rails

and then Rails 2.3.8 was installed later:

sudo gem install -v 2.3.8 rails

Now the system has both Rails 2.3.8 and 3.0.0. But if the following is typed into bash:

rails -v

Then 3.0.0 will show. Is there a way to switch to using 2.3.8 instead?

+1  A: 

Put this in your environment.rb file

RAILS_GEM_VERSION = '2.3.8' unless defined? RAILS_GEM_VERSION

If you're talking about launching rails executable from shell, then just specify correct path. Once 2.3.8 executable is launched, I don't think it can somehow find and transfer control to 3.0.0 executable.

Nikita Rybak
`/usr/bin/rails` is the rails 3.0 bin... do you know where 2.3.8 bin is? thanks.
動靜能量
@Jian Run _gem env_ and check _GEM PATHS_ section.
Nikita Rybak
+3  A: 

I recommend to have a look at the RVM tool and especially its gemsets feature.

dhofstet
A: 

I also found a way in the Agile book:

rails _2.3.8_ -v

and it will say it is version 2.3.8, although I don't know how well this approach works (how well it isolates the 2 versions of Rails) comparing to using RVM.

動靜能量
+1  A: 

Like was said above for rails 2.3 apps in environment.rb do

RAILS_GEM_VERSION = '2.3.8' unless defined? RAILS_GEM_VERSION

For rails 3 you use bundler Gemfile

gem 'rails', '3.0.0'

That above would be enough but

General advise, install rvm.

bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )

Add this to your ~/.profile.

$ [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"

Now reload the profile so the terminal knows about rvm.

$ source .profile

Run these.

$ rvm install 1.9.2      (this installs ruby 1.9.2-p0, the latest)
$ rvm 1.9.2 --default    (this sets the default implementation of ruby)
$ gem install rails
$ gem install rails -v=2.3.8 

You would then be good to go, trust me if you don't use rvm you don't know what you are missing. Then as mentioned there are gemsets too look it up here http://rvm.beginrescueend.com/gemsets/

Hugo