[英]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?如何使用 RVM 为某个目录设置默认的 ruby 版本? So that every time I
cd
into that directory, it switches to my preferred version of Ruby.这样每次我
cd
进入该目录时,它都会切换到我喜欢的 Ruby 版本。
Directly from the RVM documentation :直接来自RVM 文档:
RVM supports multiple files allowing to configure a project for automated ruby switching.
RVM 支持多个文件,允许为自动 ruby 切换配置项目。 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,
.rvmrc - 允许完全自定义环境的 shell 脚本,
- .versions.conf - key=value configuration file
.versions.conf - 键=值配置文件
- .ruby-version - single line ruby-version only
.ruby-version - 仅单行 ruby-version
- Gemfile" - comment: #ruby=1.9.3 and directive: ruby "1.9.3"
Gemfile" - 注释:#ruby=1.9.3 和指令:ruby "1.9.3"
One way is to use a Gemfile
and set the ruby version in it.一种方法是使用
Gemfile
并在其中设置 ruby 版本。 like so:像这样:
ruby '2.2.0'
then when you enter the directory you will see the following message from rvm
然后当您进入目录时,您将看到来自
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.使用您的版本信息在该目录中创建一个
.ruby-version
文件。 To set version as 2.1.2 for a directory, create the file with only "2.1.2" as the content.要将目录的版本设置为 2.1.2,请创建仅包含“2.1.2”作为内容的文件。
$ 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.或者简单地使用
rvm --ruby-version ruby_version@gemset --create
, --create 在这里将创建 gemset 如果它不存在。 If you don't need to specify a gemset, but instead use the default gemset.如果您不需要指定 gemset,而是使用默认 gemset。 leave out
@gemset --create
.省略
@gemset --create
。 ruby_version
for example 2.0.0
. ruby_version
例如2.0.0
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.