Installing Truffle on Ubuntu

Introduction

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

The steps below have been tested on:
Ubuntu 22.04 LTS

Step by step

Install nodejs

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

Use apt to install these packages, unless you know you already have them:

sudo apt install python3 curl

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

Copy this line from the above page 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 other packages that are written in native code rather than javascript. It has its own dependencies that often are not satisfied on a bare bones Ubuntu install.

Use apt to install these packages, unless you know you already have them:

sudo apt install make g++

Finally, Install Truffle

npm install -g truffle

You will see some warnings but shouldn’t see 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.

4 Likes