How to properly setup your Ruby environment using rbenv.
Using some sort of Ruby version management is highly recommended as opposed to using the system version of Ruby (which often requires sudo access to install dependencies).
1. Install Homebrew if it's not already installed:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)""brew install rbenvrbenv initNOTE: Don't forget to also add eval "$(rbenv init -)" to your ~/.bash_profile, as suggested by the output of the above command.
rbenv install 2.6.3NOTE: You can use the rbenv install --list command to list available Ruby versions.
rbenv global 2.6.3source ~/.bash_profile7. If on macOS Catalina and using Zsh (Z shell), you may encounter a write permissions error. Here's how to fix it.
Add the following to .zshenv:
export PATH="$HOME/.rbenv/bin:$PATH"
Add the following lines to .zshrc:
source $HOME/.zshenv
eval "$(rbenv init - zsh)"
Restart terminal.
The information in this guide is based on this excellent article by Jason Charnes.
The information for installing rbenv on Zsh is this article by Antonio Cangiano.