Installing Node.js and NPM on Ubuntu or Debian

Ronaldo B.August 1, 20221 min read

In this article

In this post we will show the sequence of commands necessary to install Node.js and NPM on Ubuntu or Debian, which are very common web servers.

First: Update Your System

To update your system, use the commands below:

sudo apt-get update
sudo apt-get install git-core curl build-essential openssl libssl-dev python

Second: Install Node.js

First, we will clone the Node.js repository using git.

git clone https://github.com/nodejs/node.git<font></font>
cd node

Now, inside the root directory of the Node.js repository, you can access the branch with the version you want to install. It is recommended to access the official Node site (https://nodejs.org/en/) and check the current LTS version.

In this example we will use version 12.16.1.

git checkout v12.16.1

You need to compile and install the desired version. Don’t worry, this process may take a while.

./configure
make
sudo make install

Finally, let's check if the installed version is already in effect.

node -v

Third: Install NPM

Just download the installer and run it.

curl -L https://npmjs.org/install.sh | sudo sh

Done, check if the installed version is the most up-to-date.

npm -v

Until the next article!

Keep learning with Hcode

Sign up for the course platform and follow the next blog guides.