Ruby-on-rails 如何使用 RVM 并创建全局可用的 gems?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4007171/
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
How do I use RVM and create globally available gems?
提问by GiH
I'm running Mac OSX 10.6.4 and have installed RVM. Its been great so far, I really love the way it lets me manage having multiple versions of rails and ruby on the same machine without headaches!
我正在运行 Mac OSX 10.6.4 并安装了 RVM。到目前为止它很棒,我真的很喜欢它让我在同一台机器上管理多个版本的 rails 和 ruby 的方式而不会头疼!
However, I don't want to have to install certain gems (such as passenger) for each setup. Is there a way to share gems between gemsets? I have a [email protected] and 1.9.2@rails3, can I have gems such as passenger, mysql, and capistrano installed once and used with all versions?
但是,我不想为每个设置安装某些 gem(例如乘客)。有没有办法在宝石组之间共享宝石?我有一个 [email protected] 和 1.9.2@rails3,我可以安装一次诸如passenger、mysql和capistrano之类的gem并与所有版本一起使用吗?
回答by nathanvda
There is something called the global gemset, and it is shared between all your gemsets of a certain ruby-version. But you can't share gems between ruby-versions.
有一种叫做全局 gemset 的东西,它在某个 ruby 版本的所有 gemset 之间共享。但是您不能在 ruby 版本之间共享 gem。
However, what you can do is create a list of gems that will be installed automatically when adding a new ruby version. That is described here. In short: edit a file called ~/.rvm/gemsets/global.gemsto contain the list of gems you want to be there for each ruby-version.
但是,您可以做的是创建一个 gem 列表,这些 gem 将在添加新的 ruby 版本时自动安装。这是描述here。简而言之:编辑一个名为的文件,~/.rvm/gemsets/global.gems以包含您希望为每个 ruby 版本存在的 gem 列表。
Hope it helps.
希望能帮助到你。
回答by yas375
With the latest RVM version (1.17.0 and newer) just type:
使用最新的 RVM 版本(1.17.0 和更高版本),只需键入:
rvm @global do gem install passenger
rvm @global do gem install passenger
or
或者
rvm 1.9.3@global do gem install passengerif you need it only for a specific version of ruby.
rvm 1.9.3@global do gem install passenger如果您只需要它用于特定版本的 ruby。
回答by ennuikiller
You can create and use global gemsets with the following commands:
您可以使用以下命令创建和使用全局 gemset:
rvm gemset create global
rvm gemset use global
After you've created and execute use for the global gemset simply install gems as usual:
创建并执行全局 gemset 后,只需像往常一样安装 gems:
gem install mysql passenger
回答by Justin Soliz
add the the gems you want for every gemset in a "global" rvm gemset name i.e.
在“全局”rvm gemset 名称中为每个 gemset 添加您想要的 gems,即
rvm 1.9.2@global
then project specific gemsets rvm 1.9.2@myProjectwill already have you're "default" gems from your global list
然后项目特定的 gemsetsrvm 1.9.2@myProject已经让你成为全局列表中的“默认” gems
回答by Ramiz Raja
Create and use a global gem as:
创建和使用全局 gem 为:
rvm use <ruby version>@global --create
and install gems you want to share between gemsets:
并安装要在 gemset 之间共享的 gem:
bundle install <gem name>
but these gems can only be shared between gemsets of the same Ruby version.
但是这些 gem 只能在相同 Ruby 版本的 gemset 之间共享。
回答by Jase
According to the RVM documentation, there are actually a number of "global" gemsets which can be defined at the rvm-wide level, per interpreter, per interpreter version, and finally at a specific patch-level per interpreter. And installed gems cascade from one level to the next.
根据 RVM 文档,实际上有许多“全局” gemsets 可以在 rvm 范围内定义,每个解释器,每个解释器版本,最后在每个解释器的特定补丁级别。并且安装的宝石从一个级别级联到下一个级别。

