How to install Ruby on Rails 6 on MacOS Catalina?

Photo by Flexiple.

Overview

In this tutorial we’ll be setting up Ruby on Rails 6.0 for development using macOS 10.15 Catalina.


Use oh-my-zsh

This will change your terminal from Bash to ZSH. You’ll thank me later:

  $ sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

Read more about oh-my-zsh here.


Installing Homebrew

Homebrew allows us to install packages from source on macOS.

  $ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Read more about installing Homebrew here.


Installing rbenv

We’ll be using rbenv for installing Rubies and managing Ruby versions.

  $ brew install rbenv ruby-build

We’ll then add rbenv to zshrc so that it loads every time a new session (terminal) is opened.

  $ echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.zshrc
  $ source ~/.zshrc

Install Ruby 2.7.2

We will use Ruby 2.7.2 (latest release as of November 2020) and manage our Ruby versions using rbenv.

  $ rbenv install 2.7.2
  $ rbenv global 2.7.2

Installing Ruby and Rails

As of November 2020, the latest Rails version is 6.0.3.4.

  $ gem install rails -v 6.0.3.4

Create a new Rails 6 Application with PostgreSQL and React

  $ rails new my-app —database=postgresql —webpack=react

Create the development and test databases

  $ cd my-app; bin/rails db:create

You can now visit http://localhost:3000 to view your new website!