Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use multiple versions of rubygems with rvm?

Tags:

ruby

rubygems

rvm

I have two projects on my computer: - An old Rails 2.3 app that needs rubygems 1.6 and won't run under rubygems 1.8; - A newer app that needs rubygems 1.8 and won't run under rubygems 1.6.

Each project has its own rvm gemset, but I can't figure out how to give them different versions of rubygems itself:

  • gem update --system [version] results in gem --version giving the same answer in both;
  • rvm gemset [version] has the same result.

How can I run rubygems 1.6.2 in one project and 1.8.11 in the other?


To clarify, here's what I want to do:

  • In directory A, have a .rvmrc with commands that select gemset A and rubygems 1.6.2
  • In directory B, have a .rvmrc with commands that select gemset B and rubygems latest
  • Have two terminal sessions open at the same time, one in directory A and the other in directory B
  • Type "gem --version" in directory A and see "1.6.2"
  • Type "gem --version" in directory B and see "1.8.11"
like image 655
Grandpa Avatar asked Oct 06 '11 01:10

Grandpa


People also ask

Can I use Rbenv and RVM?

Ruby environment managers such as RVM and Rbenv allow you to do just that. It is a generally accepted practice to include the . ruby-version file in the root of Ruby-written programs and applications, such as Ruby on Rails projects.

How do I install a specific version of a gem?

Use `gem install -v` You may already be familiar with gem install , but if you add the -v flag, you can specify the version of the gem to install. Using -v you can specify an exact version or use version comparators.


1 Answers

The correct way is to created different named (-n) installs of the ruby you want installed and name them according to the rubygem version you want such as

rvm --install use 1.9.2-nrg186 && rvm rubygems 1.8.6 && gem --list
rvm --install use 1.9.2-nrg1810 && rvm rubygems 1.8.10 && gem --list

The reason for this is that you can only have 1 version of rubygems active an any given time. This is also due to the fact that each ruby defines a dependency on a specific rubygems version that version is known or expected to work with (regardless of if it can work with another or not).

This is the expected way to handle the multiple rubygems requirement and to eliminate potential problems. See https://gist.github.com/1273035 for specifics detailing this.

like image 62
ddd Avatar answered Sep 30 '22 22:09

ddd