Installing Rails on macOS

Learn to install Rails on macOS

We'll cover the following

Rails with macOS

Since macOS Catalina ships with Ruby 2.6.3, skip ahead to the gem install rails line below. If running a prior version of macOS, download a newer version of Ruby that works with Rails 6. The easiest way to do this is to use Homebrew.

Exploring utilities

Before starting, go to the Utilities folder and drag the Terminal application onto the dock. You’ll be using this during the installation and frequently as a Rails developer. Open the terminal and run the following command:

> ruby -e "$(curl -fsSL \"

When it asks to install the Xcode command-line tools, say yes.

Next, there’s a choice. You can let Homebrew update your version of Ruby to the latest (currently Ruby 2.6.5), or you can install rbenv and install a parallel version of Ruby alongside the system version of Ruby.

Upgrading your version of Ruby is the most straightforward path and can be done with a single command:

$ brew install ruby

Alternatively, you can install rbenv and use it to install Ruby 2.6.5. Just be sure that you do not have RVM installed as those two applications don’t work well together.

Note that in macOS Catalina, the default shell is zsh, not bash as it had been historically. Assuming you are using Catalina and zsh, the Homebrew setup is as follows:

$ brew install rbenv ruby-build
$ rbenv init
$ echo 'eval "$(rbenv init -)"' >> ~/.zshrc $ rehash

On older versions of macOS (or if you are using bash on Catalina), the instructions are similar:

$ brew install rbenv ruby-build
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile $ ~/.rbenv/bin/rbenv init
$ hash -r

Once you’ve done that, restart the terminal by typing exit and hitting “return”. Then opening a new terminal window. After that, install Ruby like so:

$ rbenv install 2.6.5
$ rbenv global 2.6.5

If you had previously installed ruby-build and it can’t find the definition for Ruby 2.6.5, you might need to reinstall ruby-build and try again:

$ brew reinstall --HEAD ruby-build
$ rbenv install 2.6.5
$ rbenv global 2.6.5

These are the two most popular routes for Mac developers. Two alternatives are RVM and chruby.

Whichever path taken, run the following command to see which version of Ruby you’re working with:

$ ruby -v

You should see the following type of result:

ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin18]

Next, run this command to update Rails to the version used by this course:

 $ gem install rails --version=6.0.1 --no-document

Finally, install Yarn and ChromeDriver:

$ brew install yarn
$ brew tap homebrew/cask
$ brew cask install chromedriver

Get hands-on with 1200+ tech skills courses.