Search code examples
rbenv

How can I make rbenv install certain gems automatically?


I always want bundler and gem-ctags to be installed in any Ruby I have installed. Is there a way to make rbenv / ruby-build install them automatically?

RVM has @global gemsets; is there an equivalent in rbenv?


Solution

  • Use rbenv Plugins

    By default, rbenv doesn't use gemsets. People who love rbenv probably just hack their GEM_PATH and GEM_HOME when they want different gems, but there are also some plugins that automate some of this behavior. Two that I know of are:

    Use Bundler's --path Flag

    Of course, you can also just use bundler with a --path flag to install bundled gems to a unique directory instead of using gemsets. The bundle-install(1) docs say:

    --path=<path>

    The location to install the gems in the bundle to. This defaults to the gem home, which is the location that gem install installs gems to. This means that, by default, gems installed without a --path setting will show up in gem list. This setting is a remembered option.

    Consider the "Batteries-Included" RVM Instead

    The argument for rbenv is that is simpler and does less under the hood than RVM. I'd argue that if you need to add ruby-build, rbenv-gemset, and other plugins to get the functionality you need, then you may as well use RVM in the first place.

    This isn't a critique of rbenv, or praise for RVM. I'm just pointing out that if you want a tool that gives you most of RVM's functionality, you might was well just use the tool that gives you want you want "out of the box" rather than bolt the functionality on post facto.

    You can certainly do what you need to do with rbenv, one way or another. I'd just suggest that you not put yourself in a position where you have to fight your tools to get things done.