Skip to content

Install Ruby on macOS with Version Manager โ€‹

Outline โ€‹

brew install rbenv โ€‹

shell
brew install rbenv ruby-build

Setup Paths โ€‹

bash โ€‹

shell
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile

zsh โ€‹

shell
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zprofile
echo 'eval "$(rbenv init -)"' >> ~/.zprofile

Commands โ€‹

list all available versions โ€‹

shell
rbenv install -l

install a Ruby version โ€‹

shell
rbenv install 3.1.2
rbenv install 2.1.4

set ruby version for a specific dir โ€‹

shell
rbenv local 2.1.4

set ruby version globally โ€‹

shell
rbenv global 3.1.2

rbenv rehash
gem update --system

Debugging โ€‹

rbenv install 3.1.2

Bug 1 โ€‹

Problem: Could not install a ruby version

shell
brew install openssl libffi zlib readline

Bug 2 โ€‹

Error: You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.

Solution:

  1. Deleted the Gemfile.lock
  2. Run bundle

Credit โ€‹