devz-docz

Aggregation of onboarding and general devz standards that I have gatherd over my career.

View on GitHub

Ruby / Installation

Context

Installing and configuring Ruby on a Mac is a common source of confusion and frustration for folks of all experience levels due to inconsistent and incomplete instructions found online.

Although macOS ships with Ruby, it is not recommended to use it for development for several reasons:

Approaches

Limited to one version of Ruby at a time

Allows switching between multiple versions of Ruby

The Frontkomer Way

For long-term day-to-day development, I recommend installing and using Ruby via a Ruby manager. Inevitably, when working with Ruby projects, you will need to install multiple different versions at the same time and switch between them.

Depending on your preferences and needs, the two recommended ways to install and use Ruby on a Mac are via local installation of a Ruby manager, or via Docker.

Reasons to use Docker:

Local installation

The easiest and most reliable way to install Ruby locally is via an automated script which installs the following tools (only if you don’t already have them):

The script also updates your shell startup file (such as .bash_profile) to properly configure chruby.

What to do if you already have RVM or rbenv

I recommend uninstalling them before running the script.

Uninstall RVM

rvm implode

Other directories that might need to be removed:

Remove any RVM-related lines from the following files:

Quit and relaunch Terminal/iTerm

Uninstall rbenv

rm -rf ~/.rbenv

or

brew uninstall rbenv

Remove any rbenv-related lines from the following files:

Quit and relaunch Terminal/iTerm

Using Ruby via Docker

  1. Install Docker
  2. cd into the directory of the Ruby project you want to work with
  3. Run a bash shell in Docker: docker run -it --rm=true -v $PWD:$PWD -w $PWD ruby:${DESIRED_RUBY_VERSION}-slim bash

For example, if you want an image with Ruby 2.6.4, you would run:

docker run -it --rm=true -v $PWD:$PWD -w $PWD ruby:2.6.4-slim bash

Ruby managers

The most popular tools that allow you to manage multiple installations of Ruby and switch between them are: RVM, rbenv, and chruby. I recommend chruby because it is the smallest and easiest to understand. I like that it does not do some of the things that other tools do:

References: