Rubygems,Bundler和RVM之间的关系

时间:2021-09-16 07:16:13

Following current best practices, what is the proper role for each of these?

按照目前的最佳做法,每种方法的作用是什么?

Based on my limited understanding of Bundler and RVM, it seems that they--like Rubygems--have their own install locations for gems. Plus, for each one, there's the option of installing to system paths using sudo or to your home directory. And then there's the ability to vendor gems with Bundler (where applicable, e.g. with Rails).

基于我对Bundler和RVM的有限理解,它们 - 如Rubygems - 似乎有自己的宝石安装位置。另外,对于每一个,都可以选择使用sudo或主目录安装到系统路径。然后有能力使用Bundler供应宝石(适用时,例如使用Rails)。

So it looks to me like there are at least seven places to install gems now:

所以在我看来,现在至少有七个地方可以安装宝石:

  • Rubygems system path
  • Rubygems系统路径
  • Rubygems user path
  • Rubygems用户路径
  • RVM system path
  • RVM系统路径
  • RVM user path
  • RVM用户路径
  • Bundler system path
  • Bundler系统路径
  • Bundler user path
  • Bundler用户路径
  • Vendor (per-app)
  • 供应商(每个应用程序)

So, what's the best way to manage all this? Do we use all three (Rubygems, Bundler, RVM) and tell them all to install gems to the same place? Do we use sudo all the time, some of the time, or never? And should we be using a different strategy on production and development machines?

那么,管理这一切的最佳方法是什么?我们是否使用全部三个(Rubygems,Bundler,RVM)并告诉他们所有人将宝石安装到同一个地方?我们一直在使用sudo,有时候还是从不使用sudo?我们是否应该在生产和开发机器上使用不同的策略?

On a related note, are Bundler and RVM wrappers around Rubygems, are they alternatives to it, or are they completely orthogonal to it?

在相关的说明中,围绕Rubygems的Bundler和RVM包装器,它们是它们的替代品,还是它们完全正交?

2 个解决方案

#1


32  

From Bundler's website:

来自Bundler的网站:

Bundler makes it easy to make sure that your application has the dependencies it needs to start up and run without errors.

Bundler可以轻松确保您的应用程序具有启动和运行所需的依赖项,而不会出现错误。

This means that it's trivial for some other developer, or you on another machine, to get ready to develop further or use it, by running bundle install and you have everything you need to get up and running.

这意味着对于其他开发人员,或者您在另一台机器上,通过运行bundle install来准备进一步开发或使用它,并且您拥有启动和运行所需的一切,这是微不足道的。

RVM is for managing multiple versions of Ruby on the same machine, and switching between them. Gemsets is a powerful feature RVM provides that isolates gems for one application/library from the rest of your system.

RVM用于在同一台机器上管理多个版本的Ruby,并在它们之间进行切换。 Gemsets是RVM提供的一项强大功能,可将一个应用程序/库的gem与系统的其余部分隔离开来。

When using RVM and Bundler together, RVM tells Bundler where the gems should go, and Bundler installs them into the RVM-folder.

在一起使用RVM和Bundler时,RVM会告诉Bundler Gem应该去哪里,Bundler会将它们安装到RVM文件夹中。

Both (with regards to gems in RVMs case) use and depend on Rubygems, so they're closest to wrappers.

两者(关于RVM中的gems)使用并依赖于Rubygems,因此它们最接近包装器。

I, personally, use Bundler and RVM for all my projects. No gemsets, just Bundler to resolve and fix things, which it does without fail. Installing gems is done without sudo, and ends up in the place RVM defines. The default Ruby install on my system is left alone, and nothing is installed to Rubygems system/user path

我个人使用Bundler和RVM来完成我的所有项目。没有gemsets,只有Bundler来解决和修复问题,它确实没有失败。安装gems是在没有sudo的情况下完成的,最终会在RVM定义的地方完成。我的系统上的默认Ruby安装是独立的,并且没有任何内容安装到Rubygems系统/用户路径

#2


3  

The way I do it now (still experimenting a bit though) is this:

我现在这样做的方式(虽然仍在尝试一下)是这样的:

  1. Use RVM to set up the ruby version and a gemset to use for an app. I use an .rvmrc-file in the root of the app directory to make sure the correct ruby and gemset is used all the time.

    使用RVM设置ruby版本和用于应用程序的gemset。我在app目录的根目录中使用.rvmrc文件,以确保始终使用正确的ruby和gemset。

  2. Bundler is installed using gem without sudo in the given gemset.

    在给定的gemset中使用gem而不使用sudo安装Bundler。

  3. Any gems needed by the app is added to the apps Gemfile and installed using Bundler. I'm not using sudo for this.

    应用程序所需的任何宝石都会添加到应用程序Gemfile中并使用Bundler进行安装。我没有使用sudo。

This way I use Bundler to keep track of the dependencies for each app, and RVM to isolate each app's gems from each other. Works really smooth, actually.

这样我就可以使用Bundler跟踪每个应用程序的依赖关系,并使用RVM将每个应用程序的宝石相互隔离。实际上工作非常顺利。

I have not yet installed RVM on my deployment server, there I just use Bundler to make sure each apps dependecies are handled. I will probably install RVM there as well, but have to figure out how that plays ball with Passenger first.

我还没有在部署服务器上安装RVM,在那里我只使用Bundler来确保处理每个应用程序的依赖。我也可能会在那里安装RVM,但是必须先弄清楚如何与乘客一起玩。

As for your last question, Bundler is a wrapper around gem, RVM just manipulates the gempath where gems are installed. It seems to be smart enough that it picks up the gems from the same place though so I don't need to recompile any that are already installed in some other gemset.

至于你的上一个问题,Bundler是一个围绕gem的包装器,RVM只是操纵安装了gem的gempath。它似乎很聪明,它从同一个地方获取宝石,所以我不需要重新编译任何已经安装在其他gemset中的宝石。

I've stopped using sudo for installing gems after starting to use RVM. There's really no reason over just installing them in the rvm user path. I'm unsure about the best practice if you have more developers on the same machine like a test server or something like that.

在开始使用RVM之后,我已经停止使用sudo来安装gem。没有理由只在rvm用户路径中安装它们。如果你在同一台机器上有更多的开发人员,比如测试服务器或类似的东西,我不确定最佳实践。

#1


32  

From Bundler's website:

来自Bundler的网站:

Bundler makes it easy to make sure that your application has the dependencies it needs to start up and run without errors.

Bundler可以轻松确保您的应用程序具有启动和运行所需的依赖项,而不会出现错误。

This means that it's trivial for some other developer, or you on another machine, to get ready to develop further or use it, by running bundle install and you have everything you need to get up and running.

这意味着对于其他开发人员,或者您在另一台机器上,通过运行bundle install来准备进一步开发或使用它,并且您拥有启动和运行所需的一切,这是微不足道的。

RVM is for managing multiple versions of Ruby on the same machine, and switching between them. Gemsets is a powerful feature RVM provides that isolates gems for one application/library from the rest of your system.

RVM用于在同一台机器上管理多个版本的Ruby,并在它们之间进行切换。 Gemsets是RVM提供的一项强大功能,可将一个应用程序/库的gem与系统的其余部分隔离开来。

When using RVM and Bundler together, RVM tells Bundler where the gems should go, and Bundler installs them into the RVM-folder.

在一起使用RVM和Bundler时,RVM会告诉Bundler Gem应该去哪里,Bundler会将它们安装到RVM文件夹中。

Both (with regards to gems in RVMs case) use and depend on Rubygems, so they're closest to wrappers.

两者(关于RVM中的gems)使用并依赖于Rubygems,因此它们最接近包装器。

I, personally, use Bundler and RVM for all my projects. No gemsets, just Bundler to resolve and fix things, which it does without fail. Installing gems is done without sudo, and ends up in the place RVM defines. The default Ruby install on my system is left alone, and nothing is installed to Rubygems system/user path

我个人使用Bundler和RVM来完成我的所有项目。没有gemsets,只有Bundler来解决和修复问题,它确实没有失败。安装gems是在没有sudo的情况下完成的,最终会在RVM定义的地方完成。我的系统上的默认Ruby安装是独立的,并且没有任何内容安装到Rubygems系统/用户路径

#2


3  

The way I do it now (still experimenting a bit though) is this:

我现在这样做的方式(虽然仍在尝试一下)是这样的:

  1. Use RVM to set up the ruby version and a gemset to use for an app. I use an .rvmrc-file in the root of the app directory to make sure the correct ruby and gemset is used all the time.

    使用RVM设置ruby版本和用于应用程序的gemset。我在app目录的根目录中使用.rvmrc文件,以确保始终使用正确的ruby和gemset。

  2. Bundler is installed using gem without sudo in the given gemset.

    在给定的gemset中使用gem而不使用sudo安装Bundler。

  3. Any gems needed by the app is added to the apps Gemfile and installed using Bundler. I'm not using sudo for this.

    应用程序所需的任何宝石都会添加到应用程序Gemfile中并使用Bundler进行安装。我没有使用sudo。

This way I use Bundler to keep track of the dependencies for each app, and RVM to isolate each app's gems from each other. Works really smooth, actually.

这样我就可以使用Bundler跟踪每个应用程序的依赖关系,并使用RVM将每个应用程序的宝石相互隔离。实际上工作非常顺利。

I have not yet installed RVM on my deployment server, there I just use Bundler to make sure each apps dependecies are handled. I will probably install RVM there as well, but have to figure out how that plays ball with Passenger first.

我还没有在部署服务器上安装RVM,在那里我只使用Bundler来确保处理每个应用程序的依赖。我也可能会在那里安装RVM,但是必须先弄清楚如何与乘客一起玩。

As for your last question, Bundler is a wrapper around gem, RVM just manipulates the gempath where gems are installed. It seems to be smart enough that it picks up the gems from the same place though so I don't need to recompile any that are already installed in some other gemset.

至于你的上一个问题,Bundler是一个围绕gem的包装器,RVM只是操纵安装了gem的gempath。它似乎很聪明,它从同一个地方获取宝石,所以我不需要重新编译任何已经安装在其他gemset中的宝石。

I've stopped using sudo for installing gems after starting to use RVM. There's really no reason over just installing them in the rvm user path. I'm unsure about the best practice if you have more developers on the same machine like a test server or something like that.

在开始使用RVM之后,我已经停止使用sudo来安装gem。没有理由只在rvm用户路径中安装它们。如果你在同一台机器上有更多的开发人员,比如测试服务器或类似的东西,我不确定最佳实践。