Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to bundle / install gems from a local cache?

I have bunch of gems on my computer that I want to use in a chef recipe.

I know it is possible to put them in a directory like /tmp/gems and just:

cd /tmp/gems
gem install *.gem

Is it possible to put all gems in one directory where I can install them with bundler without downloading them again?

cd /somedir/my_rails_project
bundle

I want to save bandwidth.

like image 254
ayckoster Avatar asked Dec 19 '11 20:12

ayckoster


2 Answers

bundle install --local should be what you want. From the bundle-install manpage:

--local
    Do not attempt to connect to rubygems.org, instead using just the 
    gems located in vendor/cache. Note that if a more appropriate 
    platform-specific gem exists on rubygems.org, this will bypass 
    the normal lookup.
like image 191
Dieseltime Avatar answered Oct 13 '22 14:10

Dieseltime


You can use the BUNDLE_CACHE_PATH configuration key:

cache_path (BUNDLE_CACHE_PATH): The directory that bundler will place cached gems in when running bundle package, and that bundler will look in when installing gems. Defaults to vendor/bundle.

Source: https://bundler.io/v1.16/bundle_config.html#LIST-OF-AVAILABLE-KEYS

In GitLab CI, I defined this value in the environment of runners: "BUNDLE_CACHE_PATH=/cache-ci/bundle", this directory is mounted automatically in CI runners.

Then bundle install will install gems from the cache directory (once cache will be populated).

like image 34
A.L Avatar answered Oct 13 '22 14:10

A.L