0
votes

I was reading the book Rails Way. And it discusses running "bundle package". This will store all the .gem files your app uses in vendor/cache. Running bundle install will prefer gems in vendor/cache to gems in other locations. I am using rvm, so I tested this with 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

Above I created a gemset with rvm and checked if the devise gem was installed, and it was not since it is not in Gemfile. Now I use bundle package:

$ 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

Of course, no devise gem in vendor/cache either.

Then I modify Gemfile and add:

gem 'devise'

Then I run bundle install.

Now I check where devise was installed:

$ 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

So when I install a gem, it installs in the rvm folder. It does not prefer vendor/cache to other locations. If that is the case, what is the purpose of "bundle package" when you are using rvm?

1
You didn't run bundle package after adding devise. Which is why it isn't in cache, you ran install. - Doon

1 Answers

0
votes

As per my comment. You didn't run package after adding devise to your gem file which is why it isn't in vendor/cache. Bundle install still needs to install the gems on your system.

From 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.

The rvm gemset and bundler solve some of the same problems with which set of gems/versions are to be used / activated. With bundler now you don't need to use rvm gemsets , the gemfile handles it. But this wasn't always the case.