When you plan to run multiple versions of ruby, rbenv comes in handy.

Some of the commands that comes in handy when you work with rbenv are listed below

# To install rbenv (mac)
$ brew install rbenv

# To list all available ruby versions
$ rbenv install -l

# To install a specific ruby version
$ rbenv install 2.6.8

# To set the ruby version globally in the system
$ rbenv global 2.6.8

# Check what version is showing up
$ ruby -v

Sometimes, the changes may not have been added in the user shell settings. Edit ~/.bash_profile or ~/.zprofile or ~/.zshrc depending on your default shell and add in the below lines to the end of the file

# Include rbenv in ZSH shell
export PATH=”$HOME/.rbenv/bin:$PATH”
eval “$(rbenv init -)”

Save the file and open up a new terminal.

Now repeat the rbenv steps to setup the desired version and finally check the ruby version installed.