Ruby On Rails 3.2.13 - Using Different Gemsets For Rails Applications

I currently have several Rails applications running version 3.2.13 that use Ruby 1.9.3. I plan to eventually upgrade my current applications to Rails 4.0 then upgrade Ruby to 2.0. I need to time the conversion to Ruby 2.0 carefully since from my understanding Phusion Passenger will only handle one version of Ruby without some nose bleeding solutions which I do not plan to attempt to implement at this point.

I currently use one gemset for all my Rails applications. I would like to convert my Rails applications one by one from 3.2.13 to the current version of Rails 4.0 at some point. When I have tried to update one of my applications to a newer version of Rails I was told I had to do a update rails command.

What I want to do is to be able to run some of my applications using Rails 3.2.13 and others using Rails 4.0 until I am sure they will all run properly under Rails 4.0. Once I do this I will review the differences between Ruby 1.9.3 (if any) and upgrade all of them to use Rails 2.0. At this point I understand that I would just create the gemset for 2.0.0 or whatever the latest stable version of Ruby 2 is.

I have done web searches and checked the RVM website. I understand how the gemsets are assigned to the version of Ruby you want to run. However I'm not seeing anything about using gemsets with the same version of Ruby but using different versions of Rails or other combinations of gems on the same machine for different applications. Can this be done?

Any help would be appreciated.

Upvotes: 2

Views: 591

Answers (3)

Mahattam
Mahattam

Reputation: 5743

Project Folder
|___Gemfile
|__.ruby-gemset
|__.ruby-version

 Gemfile with all the required gems mention in your project folder
.ruby-gemset should have gem set name like sample-gemset
.ruby-version file should have specific ruby version (e.g 2.0)

 rvm gemset list

it will show gem set created with sample-gemset and do the

bundle install

which will install all the specific gems for this project under sample-gemset, same you can do for other project to create other gem set, in this way you can maintain different rails/gems and ruby version for different projects with rvm.

Upvotes: 1

Mike Szyndel
Mike Szyndel

Reputation: 10593

Take a closer look! ;)

First, create a new gemset with a name corresponding to your project https://rvm.io/gemsets/creating/ ex: rvm gemset create project_name

Then create/edit .rvmrc file in project directory: rvm use 1.9.3@project_name

One pitfall is that if you execute following commands

cd some_project
cd ../other_project

and other_project doesn't have gemset specified you'll stay in some_project gemset. To avoid that you can create .rvmrc file with default gemset in your "projects" directory (if you have one)

Upvotes: 2

Frederick Cheung
Frederick Cheung

Reputation: 84114

Your Gemfile.lock nails down which version of every gem you use - you don't need to worry about gemsets.

bundle install will always install the correct versions and your app will always use the versions in Gemfile.lock, even if there are other versions floating around

Upvotes: 0

Related Questions