简体   繁体   中英

Set a default Ruby version for a specific directory (RVM)

How can I use RVM to set a default ruby version for a certain directory? So that every time I cd into that directory, it switches to my preferred version of Ruby.

Directly from the RVM documentation :

RVM supports multiple files allowing to configure a project for automated ruby switching. In any case make sure to add those files to your version control systems as it is part of the project configuration.

Listed in order of precedence:

  • .rvmrc - shell script allowing full customization of the environment,
  • .versions.conf - key=value configuration file
  • .ruby-version - single line ruby-version only
  • Gemfile" - comment: #ruby=1.9.3 and directive: ruby "1.9.3"

One way is to use a Gemfile and set the ruby version in it. like so:

ruby '2.2.0'

then when you enter the directory you will see the following message from rvm

RVM used your Gemfile for selecting Ruby, it is all fine - Heroku does that too,
you can ignore these warnings with 'rvm rvmrc warning ignore /Users/danmanstx/rails_projects/app/Gemfile'.
To ignore the warning for all files run 'rvm rvmrc warning ignore allGemfiles'.

Create a .ruby-version file in that directory with your version information. To set version as 2.1.2 for a directory, create the file with only "2.1.2" as the content.

$ cat .ruby-version
2.1.2

在 rails 6 中,您只需更改应用程序文件夹中 .ruby-version 的内容

Or simply use rvm --ruby-version ruby_version@gemset --create , --create here will create the gemset if it is not present already. If you don't need to specify a gemset, but instead use the default gemset. leave out @gemset --create . ruby_version for example 2.0.0 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM