Install Ruby on Rails 7 · macOS

audience developer
level all
topic Ruby on Rails
subtopic Installation

Install Node and Yarn

Unless you create backend-only (API) Rails applications, there will always be a little (and sometimes too much) JavaScript in your Rails application.

In Rails 6, Node and Yarn were required to manage the JavaScript used by a Rails application. Rails 7 no longer depends on Node and Yarn and has new options for integrating JavaScript.

You can skip these instructions and skip ahead to install Ruby.

Install Node

You’ll need to install Node, the server version of JavaScript, before you develop any Rails applications. Node must be installed on your computer to run JavaScript in the local development environment.

Early versions of Rails only required the Ruby language for development. More recently (after Rails 5.1), Rails uses Node to run the JavaScript build tool, Webpack, to bundle together any JavaScript files used in an application. It’s difficult to develop fullstack Rails applications without installing Node.

It’s easy to install Node with asdf. Alternatively, you can download and install Node with Homebrew with brew install node, or directly from the nodejs.org website. Or you can install NVM, the Node version manager, and use NVM to install Node. I recommend keeping it simple and just installing Node with asdf.

First, be sure you've completed the section, Asdf Version Manager.

Install the asdf plugin for Node (it tells asdf how to install Node):

$ asdf plugin add nodejs
initializing plugin repository...
Cloning into '/Users/macbook/.asdf/repository'...
remote: Enumerating objects: 33, done.
remote: Counting objects: 100% (33/33), done.
remote: Compressing objects: 100% (30/30), done.
remote: Total 2633 (delta 18), reused 10 (delta 3), pack-reused 2600
Receiving objects: 100% (2633/2633), 611.28 KiB | 619.00 KiB/s, done.
Resolving deltas: 100% (1253/1253), done.

See all the versions of Node that are available:

$ asdf list all nodejs

Installation of Node requires GnuPG, the GNU Privacy Guard, to verify the authenticity of the downloaded files.

$ brew install gnupg

Verify that GnuPG was installed.

$ which -a gpg
/opt/homebrew/bin/gpg

Download and install authentication keys (to assure the Node files are authentic):

$ bash -c '${ASDF_DATA_DIR:=$HOME/.asdf}/plugins/nodejs/bin/import-release-team-keyring'

The command shows no response but you can verify the file is installed.

$ ls ~/.asdf/plugins/nodejs/bin/import-release-team-keyring

Install the latest version of Node:

$ asdf install nodejs latest

You need to specify a default version of Node in your home ~/.tool-versions file. You can set the ~/.tool-versions file with a command. Make sure to specify the Node version that was installed (here we installed version 16.3.0).

$ asdf global nodejs 16.3.0

To verify that Node is installed:

$ node --version
v16.3.0

You should see v16.3.0 or newer.

Install Yarn

Yarn is a package manager for JavaScript. It’s similar to the better-known NPM (Node Package Manager). It is used by Rails to manage JavaScript dependencies.

Install the asdf plugin for Yarn:

$ asdf plugin add yarn

See all the versions of Yarn that are available:

$ asdf list all yarn

Install the latest version of Yarn. You'll get an error if you did not install GnuPG prior to installing Node.

$ asdf install yarn latest

You need to specify a default version of Yarn in your home ~/.tool-versions file. You can set the ~/.tool-versions file with a command:

$ asdf global yarn 1.22.10

To verify that Yarn is installed:

$ yarn --version
v1.22.10

You should see v1.22.10 or newer.

Verify

You can confirm that asdf has Node and Yarn installed with the asdf info diagnostic.

$ asdf info
.
.
.
ASDF INSTALLED PLUGINS:
nodejs                       https://github.com/asdf-vm/asdf-nodejs.git
yarn                         https://github.com/twuni/asdf-yarn.git

The JavaScript build tools are now installed and ready. Next we'll install Ruby.