How To Install And Configure Node.js And npm In Ubuntu, Debian Or Linux Mint

Node.js (and npm) is available in the official Debian, Ubuntu and Linux Mint repositories, but depending on the OS version you’re using, they might have some old versions that need to be updated.
This article will explain how to install Node.js and npm from the NodeSource repository as well as how to set up npm so you can use it to properly install Node.js packages globally in your user folder, so it doesn’t mess with any permissions.An alternative way of installing Node.js and managing multiple active versions is using NVM, so you may want to check it out. This guide will use the official Node.js-provided repository instead.
These instructions are for:

  • Debian 8 (jessie), Debian 9 (stretch), Debian 10 (buster), Debian testing and Debian unstable
  • Ubuntu 19.10, 18.04 LTS, 16.04 LTS and 14.04 LTS
  • Linux Mint 17, 17.x, 18, 18.x, 19 and 19.x
  • Raspberry Pi using Debian (Raspbian) or Ubuntu, with armhf (ARM 32-bit hard-float, ARMv7) or arm64 (ARM 64-bit, ARMv8)
  • Other Linux distributions based on either the Debian or Ubuntu versions above

The Node repository does not support ARMv6, so Raspberry Pi 1 is not supported.
1. Install curl (used to download the official Node.js installation script which adds the repository and key) and build-essential (which will be used to compile and install native addons):

sudo apt install curl build-essential

2. Run the Node.js installation script (provided by
Nodejs 8 is available for all Ubuntu, Linux Mint and Debian supported versions, including Ubuntu 14.04 / Linux Mint 17. Nodejs 10, 12 and 13 are only available for Ubuntu 16.04 and newer, Debian 8 and newer, and Linux Mint 18 and newer.

  • To install Node.js 8:
curl -sL | sudo -E bash -
sudo apt install nodejs
  • To install Node.js 10:
curl -sL | sudo -E bash -
sudo apt install nodejs
  • To install Node.js 12:
curl -sL | sudo -E bash -
sudo apt install nodejs
  • To install Node.js 13:
curl -sL | sudo -E bash -
sudo apt install nodejs

The nodejs package from the official NodeSource repository includes npm.

Configure npm to install packages globally without root

Using npm installed from either the Ubuntu repositories or the Node.js repository requires running under root by default to install packages. This should be avoided, as per many articles around the web.
To get npm to install packages globally in your home folder (and add the folder to your PATH), you can use a simple script available here. This script does not work if you use NVM!
You can download the script and run it using these commands:

cd && wget
chmod +x

After following the instructions, source your .bashrc file:

. ~/.bashrc

Now you will be able to install npm packages globally without root / sudo, like this:

npm install -g <some package>

Node.js logo image is from Wikipedia.