How to Install Node.JS 14 LTS / 16 & NPM on Debian 11 Bullseye

Node.js is an open-source, cross-platform, back-end JavaScript runtime environment built on Chrome’s V8 engine to build fast and scalable network applications and back-end APIs. Node.js uses an event-driven, non-blocking IO module that makes it very lightweight and practical. It is a fantastic choice for data-intensive real-time applications that run across distributed devices.

NPM is a package manager for the JavaScript programming language maintained by NPM, Inc. NPM is the default package manager for the JavaScript runtime environment Node.js and is arguably the most available repository for Node.JS packages.

In the following tutorial, you will learn how to install Node.JS in various ways from the node source repository on Debian 11 Bullseye.

Prerequisites

  • Recommended OS: Debian 11 Bullseye
  • User account: A user account with sudo privilages or root access (su command).
  • Required Packages: 

Updating Operating System

Update your Debian 11 operating system to make sure all existing packages are up to date:

sudo apt update && sudo apt upgrade

Root or Sudo Access

By default, when you create your account at startup with Debian compared to other distributions, it does not automatically receive sudoers status. You must either have access to the root password to use the su command or visit our tutorial on How to Add a User to Sudoers on Debian.


Advertisement


Install Node.JS 14 LTS from NodeSource

The first option is to install Node.JS 14 LTS from the NodeSource repository. New users and developers were unaware of what LTS stands for means Long Term Support and is the recommended version for most users. LTS release lines focus on stability, extended support and provide a reliable platform for applications of any scale. Most Node.js users and companies are on Long Term Support lines.

To install Node.JS 14 LTS from the source, use the following curl command:

sudo curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo bash -

Next, run the apt installation command as follows to install node.js LTS 14:

npm

To verify the installation and confirm the version build of NPM, use the following command:

npm -v

Example output:

6.14.15

Given you may be swapping Node.js versions, a good idea to verify using the apt-cache policy command as well:

sudo apt-cache policy nodejs

Example output:

How to Install Node.JS 14 LTS 16 & NPM on Debian 11 Bullseye

As above, you can see the correct setup_14.x branch is installed.

To remove Node.JS 14 LTS, use the following command:

sudo apt autoremove nodejs 
sudo rm /etc/apt/sources.list.d/nodesource.list

Install Node.JS 16 from NodeSource

The second option for having the absolute latest Node.js, you will need to install Node.js 16. On the plus side of using Node.js 16, you will always have the newest build.

To install Node.JS 16 from the NodeSource, use the following curl command:

sudo curl -fsSL https://deb.nodesource.com/setup_16.x | sudo bash -

Next, run the installation apt command as follows to install node.js 16:

sudo apt install nodejs

To verify the installation and confirm the version build of node.js, use the following command:

npm -v

Example output:

7.24.0

Given you may be swapping Node.js versions, a good idea to verify using the apt-cache policy command as well:

sudo apt-cache policy nodejs

Example output:

How to Install Node.JS 14 LTS 16 & NPM on Debian 11 Bullseye

As above, you can see the correct setup_16.x branch is installed.

To remove Node.JS 16, use the following command:

sudo apt autoremove nodejs 
sudo rm /etc/apt/sources.list.d/nodesource.list

Advertisement


Updating Node.JS 14, 14LTS & 16 Source

To update Node.JS, the repository was added to your APT sources list directory, where you can draw off future updates, meaning you do not need to re-download every time a new update comes out. To check for updates using the apt update command:

sudo apt update

If an update is available, use the apt upgrade command:

sudo apt upgrade

You should regularly check for updates for your entire system, so you should quickly pick up any new additions.

Optional. Install Node.js with NVM

An alternative method to install Node.js on Debian is to use NVM, which is short for “Node Version Manager.” This handy tool works as a command line to install and manage multiple releases of Node.js on your system. This can save quite a bit of time going back and forth between versions.

To download, visit the Github release page to get the latest version.

Example only:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash

Example output if installed correctly:

How to Install Node.JS 14 LTS 16 & NPM on Debian 11 Bullseye

Once installed, run the export command or restart your terminal to activate NVM. Next, verify the version of NVM using the following terminal command:

nvm --version

Example output:

0.38.0

Next, use the nvm list-remote command to list all available node versions available:

nvm list-remote

Example output:

How to Install Node.JS 14 LTS 16 & NPM on Debian 11 Bullseye

Note that this list is extensive when using the command like the above image is just a printout sample.

Next, install a specific version of Node from the output list above. The syntax would be nvm install <version number>.

Example only:

nvm install 16.9.1

Example output:

How to Install Node.JS 14 LTS 16 & NPM on Debian 11 Bullseye

Typically, using the NVM, you will probably have more than one version of Node.js installed. To list all versions on your system, use the following command:

nvm ls

Example output:

How to Install Node.JS 14 LTS 16 & NPM on Debian 11 Bullseye

From the output list, you can run or swap to a specific version as follows:

nvm use 12.22.6

Example output:

How to Install Node.JS 14 LTS 16 & NPM on Debian 11 Bullseye

Advertisement


Comments and Conclusion

In the tutorial, you have learned how to install Node.JS & NPM on your Debian 11 Bullseye system, covering the app stream Node.JS 14 and three of the latest version options from the NodeSource repository Node.JS 14, 14 LTS, and 16. Overall, most developers would use the NodeSource repositories depending on what environment you are working in to determine which version you will use.

Leave a Comment