Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shortcut for selecting RVM gemset

Tags:

rvm

I've been dev'ing a couple apps with RoR 3.0.3 and 2.8.4, which means I have to bounce back and forth between the RVM envirnoments quite frequently. My 3.0.3 RVM is called ruby-1.9.2-p0@ror3, while the other is ruby-1.8.7-p0@ror2. Is there a faster way to switch b/w the two other than rvm use ruby-1.9.2-p0@ror3 and rvm use ruby-1.8.7-p0@ror2?

like image 333
bjork24 Avatar asked Apr 07 '11 17:04

bjork24


People also ask

How do I use Gemset?

Step 1: rvm gemset create [name of gemset] Step 2: rvm --rvmrc [ruby version here]@[name of gemset] # Note: You can check your current ruby version by running "ruby -v" from your console. Step 3: Refresh your directory. # You can simply do this by checking out of your directory and going back to that directory again.

What is RVM gemset?

RVM gives you compartmentalized independent ruby setups. This means that ruby, gems and irb are all separate and self-contained - from the system, and from each other. You may even have separate named gemsets. Let's say, for example, that you are testing two versions of a gem, with ruby 2.1.


1 Answers

Is there a faster way to switch b/w the two other than rvm use ruby-1.9.2-p0@ror3 and rvm use ruby-1.8.7-p0@ror2?

This is the exact reason that I created per-project .rvmrc files. The fundamental concept behind RVM is that it should manage your environment for you once you have everything setup and stay out of your way. So please read about the per-project .rvmrc files and add them into your workflow.

First let us create two new project directories,

$ mkdir ~/project1 ~/project2

Now we generate per-project .rvmrc files for each project,

$ cd ~/project1
$ rvm  --rvmrc --create 1.8.7@ror2

$ cd ~/project2
$ rvm --rvmrc --create 1.9.2@ror3

In order to demonstrate this let us go back to the home directory and select system ruby,

$ cd ~/

$ rvm system

$ ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]

We see here that in this case we have a system ruby installed as 1.8.7-p174 (OSX).

Now if I change directories into project1,

$ cd ~/project1

$ ruby -v
ruby 1.8.7 (2011-02-18 patchlevel 334) [i686-darwin10.6.0]

$ gem env home
/Users/wayneeseguin/.rvm/gems/ruby-1.8.7-p334@ror2

We see that we are using RVM's 1.8.7-p334 with gemset ror2

Now if we change directories into project2,

$ cd ~/project2

$ ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.6.0]

$ gem env home
/Users/wayneeseguin/.rvm/gems/ruby-1.9.2-p180@ror3

We see that we are now using 1.9.2-p180 with gemset ror3 and we did not have to manually select it :)

This is my best effort to date for having RVM stay out of your way and yet assist you in with your workflow. I hope that you find it useful and enjoy it!

You can read about using per-project .rvmrc files on the RVM documentation website.

~Wayne

like image 80
Wayne E. Seguin Avatar answered Oct 21 '22 07:10

Wayne E. Seguin