使用 rvmrc 或 ruby​​-version 文件来设置带有 RVM 的项目 gemset?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15708916/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 21:42:48  来源:igfitidea点击:

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

ruby-on-railsruby-on-rails-3ruby-on-rails-3.2rvmrvmrc

提问by Daniel Kehoe

I use RVM, the Ruby Version Managerto specify a Ruby version and a set of gems for each of my Rails projects.

我使用 RVM(Ruby 版本管理器)为我的每个 Rails 项目指定一个 Ruby 版本和一组 gem。

I have a .rvmrcfile to automatically select a Ruby version and gemset whenever I cdinto a project directory.

我有一个.rvmrc文件,可以在我cd进入项目目录时自动选择 Ruby 版本和 gemset 。

After installing RVM 1.19.0, I get a message

安装 RVM 1.19.0 后,我收到一条消息

You are using .rvmrc, it requires trusting, it is slower and it is not compatible with other ruby managers, you can switch to .ruby-versionusing rvm rvmrc to [.]ruby-versionor ignore this warnings with rvm rvmrc warning ignore /Users/userName/code/railsapps/rails-prelaunch-signup/.rvmrc, .rvmrcwill 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.

您正在使用.rvmrc,它需要信任,速度较慢,并且与其他 ruby​​ 管理器不兼容,您可以切换到 .ruby-version使用rvm rvmrc to [.]ruby-version或忽略此警告rvm rvmrc warning ignore /Users/userName/code/railsapps/rails-prelaunch-signup/.rvmrc.rvmrc将继续作为 RVM 1 和 RVM 2 中的默认项目文件,忽略警告所有文件运行rvm rvmrc warning ignore all.rvmrcs

Should I continue using my .rvmrcfile or should I switch to a .ruby-versionfile? Which is optimal? What are the ramifications?

我应该继续使用我的.rvmrc文件还是应该切换到一个.ruby-version文件?哪个是最优的?后果是什么?

回答by mpapis

If your .rvmrcfile contains custom shell code, continue using .rvmrcas it allows you to include any shell code.

如果您的.rvmrc文件包含自定义 shell 代码,请继续使用,.rvmrc因为它允许您包含任何 shell 代码。

If your only aim is to switch Ruby versions, then use .ruby-versionwhich is supported by other Ruby version switchers such as rbenvor 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.

如果您的唯一目标是切换 Ruby 版本,请使用.ruby-version其他 Ruby 版本切换器(如rbenvchruby)支持的版本。该文件也不需要信任,因为它只是 Ruby 版本的名称,不会以任何方式执行。

If you use .ruby-versionyou can include @gemsetin the file but this will not be compatible with other switchers. To maintain compatibility use the gemset name in a separate file .ruby-gemsetwhich is ignored by other tools (it works only together with .ruby-version).

如果您使用,.ruby-version您可以包含@gemset在文件中,但这将与其他切换器不兼容。为了保持兼容性,请在.ruby-gemset其他工具忽略的单独文件中使用 gemset 名称(它只能与 一起使用.ruby-version

For example, if you have a simple .rvmrc:

例如,如果您有一个简单的.rvmrc

rvm use 1.9.3@my-app

It can be transformed to .ruby-version:

它可以转换为.ruby-version

1.9.3

And .ruby-gemset:

并且.ruby-gemset

my-app

Be sure to remove the .rvmrcfile as it takes precedence over any other project configuration files:

请务必删除该.rvmrc文件,因为它优先于任何其他项目配置文件:

rm .rvmrc

回答by Sam Backus

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

从 .rvmrc 切换到 .ruby-version + .ruby-gemset 的快速简便的方法

rvm rvmrc to .ruby-version

回答by user2627938

If you want create the .ruby-versionand .ruby-gemsetfile in a short way you can use the commands like this:

如果您想以简短的方式创建.ruby-version.ruby-gemset文件,您可以使用如下命令:

rvm use 2.1.1@nancy --create

rvm --create --ruby-version 2.1.1@nancy

回答by duykhoa

You can try both. Go to the root of your project, create a .rvmrcfile (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:

你可以两个都试试。转到项目的根目录,创建一个.rvmrc文件 ( touch .rvmrc),然后编辑 rvm use 2.0.0-p451@your_gemset(您的 ruby​​ 版本和 gemset 名称)。保存此文件后,您可以键入以下命令:

cd ../your_project(you're in your_projectdirectory), and the script in .rvmrc will execute.

cd ../your_project(您在your_project目录中),并且 .rvmrc 中的脚本将执行。

The RVM recommend to use ruby-version. You can run this command to switch from .rvmrc to .ruby-version

RVM 推荐使用 ruby​​-version。您可以运行此命令从 .rvmrc 切换到 .ruby-version

rvm rvmrc to .ruby-version

rvm rvmrc to .ruby-version

What it does is create 2 files name .ruby-version, and .ruby-gemsetand add this line

它所做的是创建 2 个文件名.ruby-version.ruby-gemset并添加这一行

ruby-2.0.0-p451in .ruby-version

ruby-2.0.0-p451在 .ruby 版本中

your_gemsetin .ruby-gemset

your_gemset在 .ruby-gemset 中

You can try to do it manually if you want :)

如果你愿意,你可以尝试手动完成:)

回答by Narasu Londave

Install rvm using:

使用以下命令安装 rvm:

\curl -sSL https://get.rvm.io | bash -s stable --rails

Install different ruby versions:

安装不同的 ruby​​ 版本:

rvm install 1.8.7
rvm install 1.9.2

Switch to specific ruby version. For example, 1.8.7:

切换到特定的 ruby​​ 版本。例如,1.8.7:

rvm use 1.8.7

To create a gemse:

创建宝石:

rvm gemset create project_gemset

And to use a gemset:

并使用 gemset:

rvm gemset use project_gemset