Last Updated: October 26, 2017
· trusche

Upgrade all patch level gems with bundler

UPDATE: Looks like the next release of bundler will support the patch level options for the update command. It's included in the current edge version v1.13.0.rc.2. So this pro tip will be somewhat short lived.

With version 1.12, bundler introduced a great new option to the outdated command. You can now see outdated gems of only a particular version level - major, minor, or patch. For example:

bundle outdated --patch
bundle outdated --minor
bundle outdated --patch --minor

The missing piece is the availability of those switches for the update command. There is no bundle update --patch (yet - see above). Now this is a situation I run into all the time - updating all gems with only patch level version differences in one fell swoop. (You do have good test coverage, right?!). Here's a bit of command line hackery to get it done:

bundle update `bundle outdated --patch --porcelain|cut -d ' ' -f 1|xargs`

the --porcelain flag strips out non-essential output; the cut selects just the gem name, and finally, xargs combines all lines into a single, space-separated one. The result is exactly the list of gems you want to pass to bundle update. Cheers!