Installing Truffle on macOS

Introduction

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 depending on the shell you’re using) - the nvm install script won’t add it’s config to it automatically if you don’t have one already and it’s much easier to allow the nvm install to add it automagically:

touch .zshrc

The touch command will just set the modification date of .zshrc to now, or it will create an empty file if it does not already exist. It’s a handy way to make sure a file exists.

The nvm install docs show how but basically, copy this line and paste into a terminal:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | 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. It is very important these pre-requisite are in place or the truffle install will fail.

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

Conclusion

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

7 Likes