Installing Truffle on macOS


This note is to supplement the instructions on the official Truffle install page

The steps below have been tested on:
macOS 10.15.7 (Catalina)
macOS 12.3.1 (Monterey)

Step by step

Install nodejs

To avoid permission errors when installing packages globally npm recommends installing nodejs with a version manager.

First, install the xcode command line tools:

xcode-select --install

Install a node version manager, we will use nvm, see full instructions here

Create an empty .zshrc (or .bashrc, or other) - the nvm install script won’t add config automatically if you don’t have one:

touch .zshrc

Copy this line from the above page and paste into a terminal:

curl -o- | bash

Then install nodejs with:

nvm install --lts

Install node-gyp’s pre-requisites

The node-gyp package is a native add-on build tool, i.e. it builds packages that are written in native code rather than javascript.

The above xcode-select --install step has already installed node-gyp’s dependencies.

Finally, Install Truffle

npm install -g truffle

You will see some warnings but there shouldn’t be any errors.

Test the install with:

truffle version

and then something harder such as:

mkdir truffle_test
cd truffle_test
truffle init


Now you can return to the quickstart and explore a working truffle installation.