Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

People also ask

How do I add Gemset to RVM?

Step 1: rvm gemset create [name of gemset] Step 2: rvm --rvmrc [ruby version here]@[name of gemset] # Note: You can check your current ruby version by running "ruby -v" from your console. Step 3: Refresh your directory. # You can simply do this by checking out of your directory and going back to that directory again.

What is Gemset in RVM?

If you are using RVM(Ruby Version Manager) then using a gemset for each project is a good idea. A gemset is just a container you can use to keep gems separate from each other. Creating a gemset per project allows you to change gems (and gem versions) for one project without breaking all your other projects.

What is Ruby version file?

Many Ruby (or Rails) projects will include a simple .ruby-version file, which simply specifies a version number, for example: 2.4.2. Popular tools to help you manage your Ruby version are: Ruby Version Manager (RVM) rbenv.

What does RVM stand for ruby?

RVM stands for Ruby Version Manager. It is a command line tool which allows you to easily install, manage and work with different Ruby environments. With RVM, you can easily install different versions of Ruby and easily switch between them.


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

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

rvm rvmrc to .ruby-version

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

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