Skip to content

Instantly share code, notes, and snippets.

@jmervine
Last active February 23, 2016 23:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmervine/40cba3bcc945d4b8f21b to your computer and use it in GitHub Desktop.
Save jmervine/40cba3bcc945d4b8f21b to your computer and use it in GitHub Desktop.

How-to: Vendoring Ruby Gems

Outstanding Questions

A list of outstanding questions to be answered before finalizing this document.

  • How does on update vendored gems? Are the automatically updated when you run bundle update or do you have to run bundle package again?
  • How do you tell Heroku's build process to use bundle install --local --no-prune when building the build pack?

The purpose of this is to outline the cleanest way to vendor ruby gems from a private github repo, or private gem servers, so as not to have to commit and sensitive keys, tokens, urls, etc. while still being able to install on Heroku.

The Gemfile

First, move any and all gems that are being installed from a private gem server to instead use github.

gem 'rails'
gem 'my-private-gem', github: 'my-company/my-private-gem', tag: '0.0.1'

The Vendoring

This will store all gem files in vendor/cache as well as a copy of all github repos referred to in your Gemfile.

bundle package --no-install --all

The Install

This will install gem files stored in vendor/cache and reference the cache directory for github based gems as well in your .bundle/config.

bundle install --local --no-prune

The Gotcha

Because Rubygems doesn't support github based gems natively, bundler is providing the support for that. As such, you will need to ensure that bundler is setup in your app. (Rails should do this by default, BTW.)

# ensure bundler is setup
require 'bundler'
Bundle.setup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment