How to Install Node.js and NPM on Debian 11

Estimated reading: 4 minutes 795 views

Node.js is an open-source and cross-platform JavaScript runtime environment built on Chrome’s V8 JavaScript engine. It is designed for non-blocking, event-driven servers and is primarily used for traditional websites and back-end API services.

In this tutorial, we will show you at least three different ways to install Node.js and npm on a Debian 11 server. We believe in showing multiple methods of installing Node.js will benefit any user, since we all want to

Before starting, you have to make sure that all Debian OS packages installed on the server are up to date. You can do this by running the following commands:

apt update
apt upgrade

Method 1: Install Node.js and npm from Debian Repository

The simple and easiest way to install Node.js and npm is to install them from the Debian default repository. However, it does not contain the latest Node.js version. At the time of writing this tutorial, Node.js version 12.22.5 is included by default on Debian 11 repositories

Install the Node.js and npm with the following command:

apt install nodejs npm

Once both packages are installed, verify the Node.js version using the following command:

node -v

You should get the following output:

You can also check the npm version using the following command:

npm -v

You should get the following output:

Method 2: Install Node.js and npm from NodeSource

If you want to install a different version of Node.js than the one provided in the Debian repositories, you can use this method. NodeSource maintains an APT repository and contains multiple Node.js versions.

At the time of writing this tutorial, the NodeSource repository provides v17v16v14, and v12 versions.

We will install the LTS v16 version.

Install the curl with the following command:

apt install curl

Download and run the Node.js installation script by running the following command:

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

This will add the GPG key and Node.js repository to the APT

Note: If you want another version of Node.js  (for example 14x,) you just need to change the setup_16.x with setup_14.x.

Install the Node.js version 16.x by running the following command:

apt install nodejs

The Node.js package contains both the node and npm binaries. Once installed, verify the installed version of Node.js with the following command:

node -v

You should get the following output:

You can also verify the npm version with the following command:

npm -v

You should get the following output:

Method 3: Install Node.js and npm with NVM

NVM is also known as “Node Version Manager” is a script that allows you to manage multiple versions of Node.js.

You will need to download and install NVM in your system. You can download and run the script manually with the following command:

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

The above script makes all the required environment settings to the login script of the currently logged-in user. To apply the settings log out and log in again to your account or just execute the below command to do the same.

source ~/.bashrc

You should get the following output:

You can list all Node.js versions that can be installed with NVM using the following command:

nvm list-remote

This command will show you a long list of all Node.js versions.

Install the latest stable version of Node.js with the following command:

nvm install node

You should get the following output:

Once the installation is completed, verify the Node.js version with the following command:

node --version

You should get the following output:

You can also verify the npm version with the following command:

npm -v

You should get the following output:

If you want to install the latest LTS version, run the following command:

nvm install --lts

You can now list all installed Node.js versions using the following command:

nvm ls

You should get the following output:

If you want to switch to the current Node.js version, run the following command:

nvm use 17.5.0

You should get the following output:

To find the default Node version set for the current user, type:

nvm run default --version

Conclusion

This tutorial helped you to install Node.js and NPM on Debian 11. Additionally provided you the basic instructions to use the NVM utility.


Leave a Comment

Share this Doc

How to Install Node.js and NPM on Debian 11

Or copy link

CONTENTS