SchmidtHappens

Quickly Add an .rvmrc File to Your Project

If you are using RVM then you probably know about the .rvmrc file, but did you know that there's an easy way of creating it?

The .rvmrc file tells RVM to switch to a particular Ruby version and/or gemset for a project or folder. When you cd into the project RVM will evaluate the .rvmrc file and automatically switch to the ruby/gemset specified.

Creating this file by hand is pretty simple but there's a shortcut. Since you are most likely on the command line when you create your Ruby project you can just type the following command:

rvm --rvmrc --create ruby_version@gemset

You would just specify the Ruby version (and patch level if you'd like) and the name of the gemset you want to use. Let's say I have a project called best_thing_evar and I want to use Ruby 1.9.2 on this project. I would cd into the root of that project and type the following.

rvm --rvmrc --create 1.9.2@best_thing_evar

That's it. When you look at the files in the root folder of your project you will see a .rvmrc file.

But wait! There's more!

If you have a system or user .rvmrc file and you have the following in it…

rvm_install_on_use_flag=1

…RVM will automatically install the Ruby you specify if it is not installed instead of complaining about it not being on your system.

Something missing? Need more explanation? Let me know in the c-c-c-comments!

blog comments powered by Disqus