Use rvmrc or ruby-version file to set a project gemset with RVM?

Ruby on-RailsRuby on-Rails-3Ruby on-Rails-3.2RvmRvmrc

Ruby on-Rails Problem Overview


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?

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

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

Solution 2 - Ruby on-Rails

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

rvm rvmrc to .ruby-version

Solution 3 - Ruby on-Rails

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

Solution 4 - Ruby on-Rails

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 :)

Solution 5 - Ruby on-Rails

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDaniel KehoeView Question on Stackoverflow
Solution 1 - Ruby on-RailsmpapisView Answer on Stackoverflow
Solution 2 - Ruby on-RailsSam BackusView Answer on Stackoverflow
Solution 3 - Ruby on-Railsuser2627938View Answer on Stackoverflow
Solution 4 - Ruby on-RailsduykhoaView Answer on Stackoverflow
Solution 5 - Ruby on-RailsNarasu LondaveView Answer on Stackoverflow