与 rvm 捆绑包

bundle package with rvm

我正在看书Rails 途中。并且讨论了 运行ning "bundle package"。这将存储您的应用在 vendor/cache 中使用的所有 .gem 文件。 运行 捆绑安装将更喜欢 vendor/cache 中的 gems 而不是其他位置的 gems。我正在使用 rvm,所以我用 rvm 测试了这个:

rvm gemset create rent_prototype
rvm use 2.2.1@rent_prototype
gem install rails
rvm gemdir
/home/viggy/.rvm/gems/ruby-2.2.1@rentme_prototype
$ cd /home/viggy/.rvm/gems/ruby-2.2.1@rentme_prototype
$ ls -l devise-4.1.1
ls: cannot access devise-4.1.1: No such file or directory

上面我用 rvm 创建了一个 gemset 并检查是否安装了 gem 装置,但没有安装,因为它不在 Gemfile 中。现在我使用捆绑包:

$ cd -
$ bundle package

Updating files in vendor/cache
  * rake-11.1.2.gem
  * i18n-0.7.0.gem
  * json-1.8.3.gem
  ...
$ cd vendor/cache
$ ls -l devise-4.1.1
ls: cannot access devise-4.1.1: No such file or directory

当然,在vendor/cache中也没有设计gem。

然后我修改Gemfile,添加:

gem 'devise'

那我运行bundle install.

现在我检查设备的安装位置:

$ bundle show devise
/home/viggy/.rvm/gems/ruby-2.2.1@rentme_prototype/gems/devise-4.1.1
$ cd vendor/cache
$ ls -l devise-4.1.1
ls: cannot access devise-4.1.1: No such file or directory

因此,当我安装 gem 时,它会安装在 rvm 文件夹中。与其他位置相比,它不喜欢 vendor/cache。如果是这样,那么当您使用 rvm 时 "bundle package" 的目的是什么?

根据我的评论。在将设计添加到 gem 文件后,您没有 运行 打包,这就是它不在 vendor/cache 中的原因。捆绑安装仍然需要在您的系统上安装 gems。

来自bundler website

The package command will copy the .gem files for your gems in the bundle into ./vendor/cache. Afterward, when you run bundle install, Bundler will use the gems in the cache in preference to the ones on rubygems.org.

Additionally, if you then check that directory into your source control repository, others who check out your source will be able to install the bundle without having to download any additional gems.

rvm gemset 和 bundler 解决了一些与要使用/激活 gems/versions 组相同的问题。现在有了 bundler,你不需要使用 rvm gemsets ,gemfile 会处理它。但情况并非总是如此。