The original address: http://rvm.io/workflow/projects

RVM supports a variety of configuration files and allows you to configure a fully automated Ruby environment switch for a project. In any case, don’t forget to put those configuration files together in the version control system, because they are part of the overall project configuration file

Supported configuration files

The following files are arranged in order of processing priority:

  • .rvmrc: A Shell script that supports a fully customized project environment.
  • .versions.conf:key=valueConfiguration files.
  • .ruby-version:ruby-versionConfiguration file, which is only allowed on this line.
  • Gemfile: Project Package Dependency Files — Comments# ruby=1.9.3, efficient configurationRuby 1.9.3 "".

Note: * Only.rvmrc is supported by any version of RVM, the other files were introduced in RVM1.11.0. * Ruby environment switching for the project is only supported in RVM1.22.0 and later.

.rvmrcfile

This is the first configuration file to be supported by RVM, and it is the one with the highest processing priority. The drawback of.rvmrc is that this file needs to be trusted to prevent unverified code from running, which makes daily use a bit awkward and complicates program deployment. You should make more use of other profiles in your project when it is not necessary to use this profile.

Generate sample. RVMRC:

echo 'rvm --create use ree@tedxperth' > .rvmrc

You can also generate a more complex version:

rvm --create use ree@tedxperth --rvmrc

You can edit this file to achieve more customization.

Trust.rvmrc file:

rvm rvmrc trust /path/to/project

.ruby-versionfile

This file is also supported by ChRuby and rbenv. .ruby-version is just a version of Ruby that doesn’t need to be trusted, so it’s simpler and more convenient than.rvmrc. Generated. Ruby – version:

Echo 2.0.0 >.ruby-version # OR RVM --ruby-version use 2.0.0

Only in RVM,.ruby-version also supports gemsets in the form of ruby@gemset; other Ruby version managers do not support this feature. There are other files that can specify gemset while maintaining compatibility:.ruby-gemset.

Generated. Ruby – gemset:

Echo my_app >. ruby-gemset # OR ruby --ruby-version use 2.0.0@my_app

The second version creates both.ruby-version and.ruby-gemset files.

Some projects require additional configuration in the environment, which can be done using the.ruby-env file:

Echo "JRUBY_OPTS = - 1.9" > >. The ruby - env

This variable is set automatically when entering the project directory and is restored to its previous value when exiting the project directory.

Note the following files:

  • .rbenv-version
  • .rbenv-vars
  • .rbfu-version

They are also supported, but they have a lower processing priority than.ruby-version.

.versions.conffile

For more advanced projects,.versions.conf will be required, which is more powerful than.ruby-version.

Generate.versions.conf file:

RVM --create -- version-conf use 2.0.0@my_app

Here is an example of this file:

Ruby = works - 1.6.8 ruby - gemset = my_app env - JRUBY_OPTS = 1.9

Gemfilefile

Commands in Gemfile are supported by RVM and can be read. Example:

Ruby "2.0.0" gem "haml"

In some cases where Ruby statements are not available or more details are required, the following comments will be used in order of priority:

# # ruby = works - 1.6.8 ruby - gemset = # my_app ruby - env - JRUBY_OPTS = 1.9

Another example of using MRI Ruby in a particular Patch scenario:

# # ruby = ruby 1.9.3 - p194 ruby - gemset = my_app

These annotations are enabled if older versions of Bundler do not support the relevant statements.

RVM configuration

Some variables can be set in ~/. RVMRC and /etc/rvmrc:

  • rvm_project_rvmrc_default=1: Automatically select the default Ruby environment when the relevant configuration files for the project are not found.
  • rvm_autoinstall_bundler_flag=1: Automatic installationbundlerAnd whenGemfileRuns automatically when availablebudnle install.

Recommended resources

  • A Common .ruby-version File For Ruby Projects by Fletcher Nichol