Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RVM and automatically switching gemsets

Tags:

ruby

rvm

Is it possible to have rvm know which gemset it should be using while navigating under a certain directory, much in the same way you can have git the current branch's information just by navigating under that directory?

I understand how git works that way since each directory has its own .git directory in the root, but didn't know if it was possible since .rvm is more of a user-wide configuration. Or perhaps the answer is to make a .rvm file within each directory?

like image 638
joeellis Avatar asked Feb 28 '11 15:02

joeellis


People also ask

How do I add Gemset to RVM?

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.

How do I use Gemset?

A gemset is just a container you can use to keep gems separate from each other. Creating a gemset per project allows you to change gems (and gem versions) for one project without breaking all your other projects. Each project need only worry about its own gems. RVM provides (>= 0.1.

How do I remove Gemset?

You need to "rvm gemset empty [gemset_name]". I suppose if you have many gems, it could take a while to uninstall them all. Incidentally right now I am able to run rvm gemset empty and it clears the current gemset.


1 Answers

For others visiting this, there is a new way to do this, without having to allow arbitrary shell script to be executed in a .rvmrc file.

Create a file named .ruby-gemset containing only the gemset name in.

gemset 

Need an up to date version of rvm for this to work.

You can also specify the ruby version by creating a file named .ruby-version containing only the ruby version:

1.9.3 

This format also has the advantage of being compatible with rbenv and rbfu.

If you have existing projects using the deprecated .rvmrc, you can convert them to the new format using the command:

rvm rvmrc to .ruby-version 
like image 160
Yule Avatar answered Sep 22 '22 04:09

Yule