Build Node.js from Source

Advertisement

Advertisement

Introduction

Let's walk through the process of building Node.js from source. I'll be demonstrating this on Debian 10 Buster. The current version of Node.js in the Debian repository is v10.24. I'm going to download the newest version 15 and build it. When I'm done, I'll have the latest version node and npm executables installed on my system.

Install dependencies

First let's install the dependencies needed.

sudo apt-get install build-essential python3-distutils git

Get the source

One option is to download source from https://nodejs.org/en/download/.

NOTE: Make sure you get the right version of Node.js for your project. For example, to build VS Code from source at this time you need Node.js between v10 and v14.

Instead of downloading from the website, I'll use git to fetch the version I want.

We can list the branches and see what versions are available with git ls-remote.

git ls-remote https://github.com/nodejs/node | grep tags | less

Then to clone without full history:

git clone --depth 1 --branch v15.11.0 https://github.com/nodejs/node
cd node

Build

./configure
make -j4 # Set thread count based on CPU count
sudo make install

It took about 20 minutes for mine to build.

Run

If you did not configure any special prefix, and you ran sudo make install, it should put the executables in the /usr/local/bin/ directory.

which node
node --version

which npm
npm --version

References

Advertisement

Advertisement