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.
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.
Always install Bundler alongside Ruby with rbenv was originally published at philna.sh on March 22, 2017.
Top comments (2)
Thanks for sharing this. I am always surprised how easy to set up and useful rbenv plugins can be.
One question I had, do you use this on production servers? Or just your local development environment?
My recent production servers have been Heroku, so I already get a Ruby environment with Bundler installed.
If I was building servers with rbenv/ruby-build I think I'd prefer to codify the installation of bundler into the config and server management itself, rather than rely on this light bit of obfuscation to that process. I think this is more useful for a development machine.