bundler-gemlocal
Local Gemfile solution that works
Overview
By using bundler-gemlocal
developers can have their own custom Gemfile, called Gemlocal
by default, in addition to team-wide Gemfile
. The solution is easy to use and ensures no issues with Gemfile.lock
.
Setup
- Download
bundler-gemlocal.sh
into your home directory:
$ cd
$ curl https://raw.githubusercontent.com/dadooda/bundler-gemlocal/master/bundler-gemlocal.sh -O
- Edit your user's shell startup files to source
bundler-gemlocal.sh
. I recommend.bashrc
. If you don't have one, edit.profile
:
$ echo -e "\n. bundler-gemlocal.sh" >> .bashrc
- Reload your shell (Mac users: open new Terminal window). Then check that
b
function is available:
$ type -t b
function
Usage
b
is a Gemlocal-aware alias tobundle
.bx
is a Gemlocal-aware alias tobundle exec
.
Examples:
$ b install --path vendor/bundle
$ b check
$ bx gem list -l
$ bx rails console
etc.
Project setup example
- Cd to your project directory:
$ cd /path/to/project
- Edit
.gitignore
:
/Gemlocal
/Gemlocal.lock
- Edit
config/boot.rb
or the file which initializes Bundler in your project:
ENV["BUNDLE_GEMFILE"] ||= File.exists?(fn = File.expand_path("../../Gemlocal", __FILE__)) ? fn : File.expand_path("../../Gemfile", __FILE__)
- Edit
Gemlocal
:
# Source the main Gemfile.
eval_gemfile File.expand_path("../Gemfile", __FILE__)
group :development do
# Console enhancements etc.
gem "irb_hacks"
gem "ori"
gem "rdoc"
gem "wirb"
# etc.
end
- Install the local bundle for the first time:
$ b install
- Add
Gemlocal.example
:
$ curl https://raw.githubusercontent.com/dadooda/bundler-gemlocal/master/Gemlocal.example -O
- All done! From now on, keep editing both
Gemfile
andGemlocal
as you like. Then do ab install
and it'll sort everything out for you.
Gemfile.local
?
Why not - Because I like this:
$ ls -1 Gem*
Gemfile # o
Gemfile.lock # o
Gemlocal # -
Gemlocal.lock # -
more than this:
$ ls -1 Gem*
Gemfile # o
Gemfile.local # -
Gemfile.local.lock # -
Gemfile.lock # o
Legend: (
o
: in the repo,-
: not in the repo).
- Because "Gemlocal" is both a term and a filename, just like "Gemfile". It's more documentation-friendly.
- Because the blogs are full of half-working
Gemfile.local
recipes which will cause you nothing but pain. Find this page by the word "Gemlocal" and stay trouble-free!
Cheers!
Feedback of any kind is highly appreciated.
— Alex Fortuna, © 2015-2016