安装Ruby gem的正确方法是什么?使用RVM还是Bundler?

时间:2023-02-02 00:18:25

I am following these instructions: https://github.com/phifty/agraph/blob/master/README.rdoc, and there is a step to install a gem using this command:

我遵循这些说明:https://github.com/phifty/agraph/blob/master/README.rdoc,并且使用此命令安装gem的步骤如下:

gem install agraph

I am new to RoR, but I have RVM and Bundler. I am not sure which I should use. Should I install this using RVM or Bundler? What should be the command?

我是RoR的新手,但我有RVM和Bundler。我不确定应该使用哪个。我应该使用RVM还是Bundler安装它?命令应该是什么?

2 个解决方案

#1


8  

RVM is Ruby Version Manager. It lets you maintain separate installs of Ruby side-by-side without conflicts, easily. One of the requisites for doing this is keeping gems for each version of Ruby separate since the installers can "toggle" based on which version of Ruby you're running.

RVM是Ruby Version Manager。它允许您轻松地并行地维护单独的Ruby安装而不会发生冲突。这样做的一个必要条件是保持每个Ruby版本的宝石分开,因为安装程序可以根据您运行的Ruby版本进行“切换”。

Gem is a command that lets you install gems. It's the core of the whole infrastructure – it doesn't call out to a lower-level "packager" to do its work.

Gem是一个允许您安装宝石的命令。它是整个基础设施的核心 - 它不会召集较低级别的“打包者”来完成其工作。

Bundler runs "on top" of Gem. It makes managing gem versions easier, much like RVM does for Rubies (versions of Ruby). It'll automatically install gems that aren't installed, so you don't need to explicitly run gem install gem-name before running bundle (or bundle install).

Bundler在Gem的“顶部”运行。它使得管理gem版本变得更容易,就像RVM对Rubies(Ruby的版本)所做的那样。它会自动安装未安装的gem,因此在运行bundle(或bundle install)之前不需要显式运行gem install gem-name。


Gem, Bundler, and RVM all cross paths if you start using RVM's gemsets. They allow you to further isolate and control your environment by creating a separate "gem environment" of sorts. The primary use for this is so that you can keep gems for different projects separate, which aids in managing versions. If you use Bundler, this isn't really as important or useful as in pre-Bundler days where Rails/Sinatra/etc. would require the most recent version of a gem.

如果您开始使用RVM的gemsets,Gem,Bundler和RVM都会交叉路径。它们允许您通过创建各种各样的“宝石环境”来进一步隔离和控制您的环境。这样做的主要用途是,您可以将不同项目的宝石分开,这有助于管理版本。如果您使用Bundler,这在使用Rails / Sinatra / etc的Bundler之前的日子里并不那么重要或有用。需要最新版本的宝石。

Does that answer your question?

这是否回答你的问题?

#2


2  

If you are using Rails 3 you should put the command in your application Gemfile

如果您使用的是Rails 3,则应将该命令放在应用程序Gemfile中

gem 'agraph'

then run bundle install. This will take care of dependency resolution and bundling the gem on your production servers when you deploy.

然后运行bundle install。这将在部署时负责依赖性解析并在生产服务器上捆绑gem。

For RVM the only thing you might want to do is set an RVM gemset for your application. You can do this by creating a .rvmrc file in your application directory, which will automatically set the RVM ruby version and gemset when you enter into that directory. You should not manually install gems for your application using RVM.

对于RVM,您可能想要做的唯一事情是为您的应用程序设置RVM gemset。您可以通过在应用程序目录中创建.rvmrc文件来执行此操作,该文件将在您进入该目录时自动设置RVM ruby​​版本和gemset。您不应使用RVM手动为应用程序安装gem。

#1


8  

RVM is Ruby Version Manager. It lets you maintain separate installs of Ruby side-by-side without conflicts, easily. One of the requisites for doing this is keeping gems for each version of Ruby separate since the installers can "toggle" based on which version of Ruby you're running.

RVM是Ruby Version Manager。它允许您轻松地并行地维护单独的Ruby安装而不会发生冲突。这样做的一个必要条件是保持每个Ruby版本的宝石分开,因为安装程序可以根据您运行的Ruby版本进行“切换”。

Gem is a command that lets you install gems. It's the core of the whole infrastructure – it doesn't call out to a lower-level "packager" to do its work.

Gem是一个允许您安装宝石的命令。它是整个基础设施的核心 - 它不会召集较低级别的“打包者”来完成其工作。

Bundler runs "on top" of Gem. It makes managing gem versions easier, much like RVM does for Rubies (versions of Ruby). It'll automatically install gems that aren't installed, so you don't need to explicitly run gem install gem-name before running bundle (or bundle install).

Bundler在Gem的“顶部”运行。它使得管理gem版本变得更容易,就像RVM对Rubies(Ruby的版本)所做的那样。它会自动安装未安装的gem,因此在运行bundle(或bundle install)之前不需要显式运行gem install gem-name。


Gem, Bundler, and RVM all cross paths if you start using RVM's gemsets. They allow you to further isolate and control your environment by creating a separate "gem environment" of sorts. The primary use for this is so that you can keep gems for different projects separate, which aids in managing versions. If you use Bundler, this isn't really as important or useful as in pre-Bundler days where Rails/Sinatra/etc. would require the most recent version of a gem.

如果您开始使用RVM的gemsets,Gem,Bundler和RVM都会交叉路径。它们允许您通过创建各种各样的“宝石环境”来进一步隔离和控制您的环境。这样做的主要用途是,您可以将不同项目的宝石分开,这有助于管理版本。如果您使用Bundler,这在使用Rails / Sinatra / etc的Bundler之前的日子里并不那么重要或有用。需要最新版本的宝石。

Does that answer your question?

这是否回答你的问题?

#2


2  

If you are using Rails 3 you should put the command in your application Gemfile

如果您使用的是Rails 3,则应将该命令放在应用程序Gemfile中

gem 'agraph'

then run bundle install. This will take care of dependency resolution and bundling the gem on your production servers when you deploy.

然后运行bundle install。这将在部署时负责依赖性解析并在生产服务器上捆绑gem。

For RVM the only thing you might want to do is set an RVM gemset for your application. You can do this by creating a .rvmrc file in your application directory, which will automatically set the RVM ruby version and gemset when you enter into that directory. You should not manually install gems for your application using RVM.

对于RVM,您可能想要做的唯一事情是为您的应用程序设置RVM gemset。您可以通过在应用程序目录中创建.rvmrc文件来执行此操作,该文件将在您进入该目录时自动设置RVM ruby​​版本和gemset。您不应使用RVM手动为应用程序安装gem。