Here’s a quick tip for anyone who uses rbenv and ruby-build to manage installing and switching Ruby versions.

When installing a new version of Ruby I cannot think of a situation in which I wouldn’t want Bundler installed too. The good news is that you can get rbenv to install Bundler, or any other gem you like, as soon as you install a new version of Ruby. All you need is the default-gems plugin.

Default gems

If you installed rbenv with Homebrew, like me, then you can install default-gems with Homebrew too.

$ brew install rbenv-default-gems

Then you need to make a list of gems that you want installed. First create a file named default-gems in your $(rbenv root) directory. Mine is located at ~/.rbenv/default-gems. Add the names of the gems you want to install, one per line. You can include an optional version or the option --pre for a prerelease version. For Bundler you will want the latest release, so the default-gems file would look like this:

bundler

Now when you install a new version of Ruby, Bundler will be installed as well.

A terminal window shows the result of running `rbenv install 2.4.0`. Not only is Ruby 2.4.0 installed, but so is the latest version of Bundler.

You can add other gems that you always use too. If you’re a fan of pry, for example, then add a line for it in default-gems and you’ll never have to remember to install it yourself.

rbenv plugins

There are a number of rbenv plugins which you can check out, but default-gems has always been a must have for me.

Are there any tools or plugins you use that make your Ruby development easier? I’d love to hear about them! Please share your tips with me on Twitter.