235

I use RVM, the Ruby Version Manager to specify a Ruby version and a set of gems for each of my Rails projects.

I have a .rvmrc file to automatically select a Ruby version and gemset whenever I cd into a project directory.

After installing RVM 1.19.0, I get a message

You are using .rvmrc, it requires trusting, it is slower and it is not compatible with other ruby managers, you can switch to .ruby-version using rvm rvmrc to [.]ruby-version or ignore this warnings with rvm rvmrc warning ignore /Users/userName/code/railsapps/rails-prelaunch-signup/.rvmrc, .rvmrc will continue to be the default project file in RVM 1 and RVM 2, to ignore the warning for all files run rvm rvmrc warning ignore all.rvmrcs.

Should I continue using my .rvmrc file or should I switch to a .ruby-version file? Which is optimal? What are the ramifications?

chris Frisina
  • 19,086
  • 22
  • 87
  • 167
Daniel Kehoe
  • 10,952
  • 6
  • 63
  • 82

5 Answers5

382

If your .rvmrc file contains custom shell code, continue using .rvmrc as it allows you to include any shell code.

If your only aim is to switch Ruby versions, then use .ruby-version which is supported by other Ruby version switchers such as rbenv or chruby. This file also does not require trusting as it is just the name of a Ruby version and will not be executed in any way.

If you use .ruby-version you can include @gemset in the file but this will not be compatible with other switchers. To maintain compatibility use the gemset name in a separate file .ruby-gemset which is ignored by other tools (it works only together with .ruby-version).

For example, if you have a simple .rvmrc:

rvm use 1.9.3@my-app

It can be transformed to .ruby-version:

1.9.3

And .ruby-gemset:

my-app

Be sure to remove the .rvmrc file as it takes precedence over any other project configuration files:

rm .rvmrc
wpp
  • 7,093
  • 4
  • 33
  • 65
mpapis
  • 52,729
  • 14
  • 121
  • 158
  • 10
    Note that not all applications yet support the newer .ruby-version and .ruby-gemset files but only .rvmrc. (RubyMine in particular). This of course would effect your choice of whether to move to the new system. I had already pointed this out in an answer as it took me alot of time to track this down. However my answer was removed for some reason.. – giorgio Apr 15 '13 at 23:29
  • 2
    Is there a link to any "official" documentation on this? I started looking into how this works in the RVM site but just found some vague mention to it as the new rvmrc file but nothing as to how this should work. – eirc May 01 '13 at 13:14
  • 2
    It's not fully documented, but here is what we have already https://rvm.io/workflow/projects/#ruby-versions – mpapis May 01 '13 at 18:45
  • 4
    Simply place 1.9.3-p194 into .ruby-version not work for me. Refer to the document above, `rvm --create --ruby-version use 1.9.3-p194` do the work, and the content inside is actually `ruby-1.9.3-p194` – Jinzhao Huo Jul 29 '13 at 04:15
  • if it did not worked - open a bug for rvm => https://github.com/wayneeseguin/rvm/issues – mpapis Jul 29 '13 at 05:04
  • Previously I had rvm_gemset_create_on_use_flag=1 in my .rcmrc file. How can I get the same functionality by using .ruby-profile and .ruby-gemset ? – Andreas Nov 09 '13 at 12:08
  • the create on use is enabled by default for .ruby-gemset – mpapis Nov 09 '13 at 23:02
  • 2
    Current versions of RubyMine do support the .ruby-version style. Can confirm with 6.3.2 – BeepDog May 15 '14 at 00:53
76

Quick and easy way to switch from .rvmrc to .ruby-version + .ruby-gemset

rvm rvmrc to .ruby-version
Sam Backus
  • 1,693
  • 14
  • 19
  • 1
    True, but it puts [] around the . for some reason that I haven’t figured out. (maybe this is a convention I’m unfamiliar with.) I actually googled the message and found this answer because the awkward phrasing and the [] made me unsure what to actually run. – zem Apr 01 '14 at 22:52
  • 2
    @zem The [] in `[.]ruby-version` indicate that [the dot is optional](https://github.com/wayneeseguin/rvm/issues/1708#issuecomment-22437586); the square brackets are a common convention to indicate optionality (in general, not in ruby.) So you could use a file called "ruby-version", without the dot, and that would also be used. This can be useful if you want more visibility of the file on systems that hide "dot files" by default. I agree it's not that clear, though. – Matt Gibson Dec 15 '14 at 11:07
  • It says `Could not load .rvmrc` – Abdullah Aug 10 '17 at 07:15
4

If you want create the .ruby-version and .ruby-gemset file in a short way you can use the commands like this:

rvm use 2.1.1@nancy --create

rvm --create --ruby-version 2.1.1@nancy
SgtPooki
  • 11,012
  • 5
  • 37
  • 46
user2627938
  • 207
  • 2
  • 3
3

You can try both. Go to the root of your project, create a .rvmrc file (touch .rvmrc), then edit rvm use 2.0.0-p451@your_gemset (your ruby version and gemset name). After save this file, you can type this command:

cd ../your_project (you're in your_project directory), and the script in .rvmrc will execute.

The RVM recommend to use ruby-version. You can run this command to switch from .rvmrc to .ruby-version

rvm rvmrc to .ruby-version

What it does is create 2 files name .ruby-version, and .ruby-gemset and add this line

ruby-2.0.0-p451 in .ruby-version

your_gemset in .ruby-gemset

You can try to do it manually if you want :)

duykhoa
  • 2,227
  • 1
  • 25
  • 43
-1

Install rvm using:

\curl -sSL https://get.rvm.io | bash -s stable --rails

Install different ruby versions:

rvm install 1.8.7
rvm install 1.9.2

Switch to specific ruby version. For example, 1.8.7:

rvm use 1.8.7

To create a gemse:

rvm gemset create project_gemset

And to use a gemset:

rvm gemset use project_gemset
Community
  • 1
  • 1