Last updated: Aug 5, 2022
The following guide is based on MacOS Monterey (12.0).
Homebrew is a package manager for MacOS.
Install it by copying the following command into a terminal window:
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Agree to install XCode Command Line Tools if the installer asks. Read the installer's output, and follow any other instructions provided, such as adding Homebrew to your PATH.
Create an SSH private-public key pair to facilitate logging in to remote machines without typing a password. Copy the command below, customizing login@hostname with your own information.
$ ssh-keygen -t ed25519 -C "login@hostname"
When prompted, accept the default location (~/.ssh/id_ed25519)
and default passphrase (i.e., empty for none).
Install rbenv as well as ruby-build (a plugin for installing Ruby).
$ brew install rbenv ruby-build
After installation, add rbenv to the shell.
$ echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.zshrc
$ source ~/.zshrc
Install Ruby.
$ rbenv install 3.1.2 # this step takes several minutes
$ rbenv global 3.1.2 # set default ruby version
$ ruby -v # confirm it works
If ruby is not found or if ruby -v shows the wrong version, you may need to close and re-open your terminal
Install Rails.
$ gem install --no-document rails -v 7.0
Confirm Rails installation with a simple smoke test.
$ mkdir rails_work
$ cd rails_work
$ rails new demo
$ cd demo
$ rails server
If rails is not found, you may need to close and re-open your terminal
The output of the last command should look something like:
=> Booting Puma
=> Rails 7.0.x.y application starting in development
=> Run `bin/rails server --help` for more startup options
Puma starting in single mode...
* Puma version: 5.6.4 (ruby 3.1.2-pxx) ("Birdie's Version")
* Min threads: 5
* Max threads: 5
* Environment: development
* PID: 18440
* Listening on http://127.0.0.1:3000
* Listening on http://[::1]:3000
Use Ctrl-C to stop
You can kill the server with Ctrl-C (in the terminal window in which it is running):
^C- Gracefully stopping, waiting for requests to finish
=== puma shutdown: yyyy-mm-dd hh:mm:ss -0400 ===
- Goodbye!
Exiting
Install Node (not needed for Rails, but we'll be using it too).
$ brew install wget
$ wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
$ nvm install 16 --lts If nvm is not found, you may need to close and re-open your terminal