If you are not a ruby developer, a ruby version manager might be overkill if you only need it from time to time.
direnv is a tool that manages your environment depending on the current
directory1. At first, I started using it to manage environment variables
for specific projects. After that, it replaced version managers for languages
everything neatly configured in
.envrc files, it made sense to include the
ruby version as well.
$ brew install direnv
First, install direnv and configure your shell to use it.
$ brew install chruby
Then install chruby2, but do not configure your shell to source it.
Instead, we will do this via direnv. Edit
~/.direnvrc and append the
If your ruby versions are not in
~/.rubies, uncomment the
RUBIES line and
set the value appropriately.
Relaunch your shell, navigate to your project, run
direnv edit ., and add
the following (assuming you have 2.5.1 installed):
use ruby 2.5.1
Your shell should now be ready with the specified ruby version.
(See also: Manage project dependencies with direnv.)