Today I learned

Bundle your gems inside your project

When working on a Ruby project, I always put the files in vendor/bundle/. This has the benefit of having a greppable index of all the gems of your project, while keeping your global gemset tidy.

bundle install -j3 --path=vendor/bundle

You only need to do this once in your project. The --path setting will be persisted in your project's Bundler configuration (.bundle/config).

Next: Why would we want to do this?

Inspecting your gems

Doing this will make inspecting your gem code easier. This can be conveniently done with something like ack or the silver searcher:

$ cd vendor/bundle/ruby/*/gems
$ ag all_application_helpers

  106:   def all_application_helpers
Next: How do we ignore this from all repos?

Globally ignoring

I recommend placing vendor/bundle/ on a global gitignore. If you haven't set up a global gitignore list yet, it's pretty easy.

git config --global core.excludesfile ~/.gitignore
echo vendor/bundle >> ~/.gitignore

Goodbye, rvm!

This removes the need for managing gemsets via rvm. In fact, if your project always uses the latest Ruby (which you also should, in my opinion!), you won't even need rvm at all.

Even if you don't use this tip, you actually don't need rvm gemsets at all. Bundler solves the same problem.

Next: Bonus: let's speed up our installations!

Parallel installs

Bonus: the -j3 flag makes your installations faster by allowing 3 installs in parallel.

You have just read Bundle your gems inside your project, written on June 22, 2015. This is Today I Learned, a collection of random tidbits I've learned through my day-to-day web development work. I'm Rico Sta. Cruz, @rstacruz on GitHub (and Twitter!).

← More articles