Sometimes I have to use a fork of a gem for a bug fix and I have to bundle my gems locally for deployment on a server that isn’t connected to the public internet. This presents a problem because bundler doesn’t locally save gems with git sources but it will save gems with github sources.

Here are the steps to get it to save locally. First add your gem like this in your Gemfile:

# Gemfile
gem 'chosen-rails', github: "westonganger/chosen-rails", branch: :master

Next run bundle install --path vendor/cache

Now change your Gemfile to use the git source so that when you try to bundle install on the server without internet access it wont try to connect.

# Gemfile
gem 'chosen-rails', git: "", branch: :master

Next run bundle install --path vendor/cache again to update your Gemfile.lock with the changes

Now it will be saved in /vendor/cache and be loaded locally when you bundle install --local on your server.

Related External Links: