RVM and automatically switching gemsets

Create a .rvmrc file in each project/branch with contents similar to this:

rvm gemset use xxxx

Save it. Next time you cd into that folder, you'll probably get a security prompt from RVM to make sure you want to use that .rvmrc. After accepting, you'll see "Now using gemset 'xxxx'" every time you navigate into that folder.


I find the easiest way to achieve this is to navigate to the project folder and then use the following command:

rvm --rvmrc --create <ruby>@<desired-gemset-name>

e.g. rvm --rvmrc --create 1.9.2-p290@testing_gemset

In one stroke, RVM will create the .rvmrc file, populate it, install the correct ruby version - if necessary - and (usually) switch to the correct ruby version and gemset. I say usually because I find that I sometimes have to cd . after performing that command to get RVM to pick up the changes.


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

Create a .ruby-version file with the contents [ruby version]@[gemset] in the project folder.

Example:

$ rvm gemset list

    gemsets for ruby-2.6.3 (found in /home/ec2-user/.rvm/gems/ruby-2.6.3)
       (default)
       hello
    => sample
       toy

$ echo "2.6.3@sample" > .ruby-version

Tags:

Ruby

Rvm