34

For my different Rails folders, I would like to have rvm automatically load the correct gemset when running anything from 'bundle install' to doing my 'autotest' or rails console or server. Is this possible? Currently I have to manually do 'rvm use' which is getting a bit tedious as I am working on multiple Rails projects at the same time.

Etienne
  • 726
  • 1
  • 7
  • 18

7 Answers7

42

Create a .rvmrc file in your rails directory, and rvm will automatically load it. An example .rvmrc that loads Ruby 1.9.2 and a gemset named "rails3":

.rvmrc

rvm 1.9.2@rails3

You can do a lot more too, described in detail here: https://rvm.io/workflow/rvmrc/

mpapis
  • 52,729
  • 14
  • 121
  • 158
Dominic
  • 3,304
  • 19
  • 22
33

For current versions of RVM, using two files is best practice:

.ruby-version
.ruby-gemset

http://rvm.io/workflow/projects

dangerousdave
  • 6,331
  • 8
  • 45
  • 62
  • 2
    This is correct, the idea being that the .rvmrc file was RVM-specific whereas these files are version-manager agnostic. I am not sure if chruby / rbenv support both of these yet or not though. – Brett Bender Feb 12 '14 at 21:29
7

For current RVM version 1.29.1, the recommended way is

rvm --ruby-version use <ruby-version>@<gemset>

Exmaple

rvm --ruby-version use 2.4.0@rails5
cat .ruby-version  # 2.4.0
cat ruby-gemset # rails5

this will generate two file .ruby-version and .ruby-version in your porject directory. This will compatible with other Ruby Versions Managers

Fangxing
  • 5,716
  • 2
  • 49
  • 53
6

You can also use this in Gemfile

ruby '2.2.0'
ruby-gemset=significa

This way rvm will automatically pick the configured version

Bruno Peres
  • 2,980
  • 1
  • 21
  • 19
Simonini
  • 623
  • 9
  • 25
5

Yaw just create two plain-text files and put into your project folder: .ruby-gemset and .ruby-version

.ruby-gemset should contain only gemset alias name and nothing else

.ruby-version follows the same rules, put your ruby version or alias there

2

You can easily do that by placing an .rvmrc file at the base of your project.

mpapis
  • 52,729
  • 14
  • 121
  • 158
picardo
  • 24,530
  • 33
  • 104
  • 151
0

I had the same problem. But, I found I had installed a ruby version globally while installing rvm.

I uninstalled that global version and everything started to work fine with .ruby-version and .ruby-gemset file in project's root directory.