Skip to content

Instantly share code, notes, and snippets.

@lfzawacki
Created August 7, 2015 00:37
Show Gist options
  • Save lfzawacki/6434abc13554c2b361c9 to your computer and use it in GitHub Desktop.
Save lfzawacki/6434abc13554c2b361c9 to your computer and use it in GitHub Desktop.
Using local Gemfiles

Using local Gemfiles

This is useful if you're working on a project with other developers and want to use different gems locally that you don't have to commit to the repository.

Get the Gemfile.local file

From this repository https://github.com/gerrywastaken/Gemfile.local. The rest the instructions here are mostly based on what is written there with some modifications.

Add new gems and run bundle install

First copy your Gemfile.lock to Gemfile.local.lock . Add your new gems to Gemfile.local and run:

BUNDLE_GEMFILE="Gemfile.local" bundle install

Running rails commands with the new Gemfile

You can run it with the BUNDLE_GEMFILE variable set, for example:

BUNDLE_GEMFILE="Gemfile.local" bundle exec rails s

If you don't want to prefix all commands with this variable you can put this in your ~/.bashrc

# When entering a directory with Gemfile.local set it as default Gemfile
function cd
{
  builtin cd "$@"
  if [ -f "Gemfile.local" ]
  then
    export BUNDLE_GEMFILE="Gemfile.local"
  else
    export BUNDLE_GEMFILE=""
  fi
}

Ignore the files

Put Gemfile.local and Gemfile.local.lock in .gitignore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment