How To Install Node.js on Debian 11

In this article, we want to teach you How To Install Node.js on Debian 11.

Node.js is a free and open-source server environment. It runs on different platforms like Windows, Linux, Unix, Mac OS X, etc. It can generate dynamic page content. Also, Node.js can create, open, read, write, delete, and close files on the server. and it can add, delete, and modify data in your database.

How To Install Node.js on Debian 11

In this article, we show you install Node.js on Debian 11 in different ways:

  1. Install Node.js from the default Debian repository.
  2. Use the PPA repository.
  3. Use NVM (Node Version Manager) to install and activate different versions of Node.

Then we will show you how to remove Node.js from your server.

You need to log in to your server as a non-root user with sudo privileges. To do this you can check our article about the Initial server setup with Debian 11.

Install Node.js from the default Debian repository

To get Node.js from the default Debian repository, you can use the APT package manager.

First, update your local package index with the following command:

sudo apt update

Then, install the Node.js package, and the NPM, Node Package Manager, with the following command:

sudo apt install nodejs npm

You can verify that your installation was successful by checking the Node.js version with the following command:

node -v

In your output you will see:

Output
v12.22.5

Install Node from the PPA repository

You can install Node.js from a PPA (personal package archive) maintained by NodeSource.

NodeSource has PPAs available for Node versions from 0.10 through to 12.

Use curl to get the installation script for your preferred Node.js version. Remember to replace the 12.x with your preferred version:

curl -sL https://deb.nodesource.com/setup_12.x -o nodesource_setup.sh

Then run the installation script with the following command:

sudo bash nodesource_setup.sh

The PPA will be added to your configuration and your local package cache will be updated automatically. Now you can install the Node.js package on Debian 11 in the same way you did in the previous step:

sudo apt install nodejs

You can verify the installation with the following command:

Output
v12.22.5

At this point, you don’t need to install a separate package for NPM.

NPM uses a configuration file in your home directory to keep track of updates. It will be created the first time you run npm.

Use the following command to verify that npm is installed and create the configuration file:

npm -v

If you want to have the necessary tools to work with npm packages that require compiling code from source, you can use the following command:

sudo apt install build-essential

Install Node.js with NVM

You can download the NVM installation script from the Project’s GitHub Page, with the curl tool.

Note that the version number may differ from what is here in this command:

curl -sL https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh -o install_nvm.sh

Then run the NVM installation script with the following command:

bash install_nvm.sh

You don’t need sudo here because nvm is not installed into any privileged system directories. To get access to the NVM functionality, you need to source the ~/.profile file so that your current session knows about the changes:

source ~/.profile

To list the available Node.js versions on Debian 11 run the following command:

nvm ls-remote

In your output you will see:

Output
...
v14.18.1 (Latest LTS: Fermium)
v15.0.0
v15.0.1
v15.1.0
v15.2.0
v15.2.1
v15.3.0
v15.4.0
v15.5.0
v15.5.1
v15.6.0
v15.7.0
v15.8.0
v15.9.0
v15.10.0
v15.11.0
v15.12.0
v15.13.0
v15.14.0
v16.0.0
v16.1.0
v16.2.0
v16.3.0
v16.4.0
v16.4.1
v16.4.2
v16.5.0
v16.6.0
v16.6.1
v16.6.2
v16.7.0
v16.8.0
v16.9.0
v16.9.1
v16.10.0
v16.11.0
v16.11.1

As you can see the current LTS version is v14.18.1. you can install it with the following command:

nvm install 14.18.1

You can verify the Node.js installation on Debian 11 with the following command:

node -v

Your output should similar to this:

Output
v14.18.1

You can check what version of Node.js is installed on Debian 11 with the following command:

nvm ls

If you want to use each of them in default you can use the following command:

nvm alias default 14.18.1

You can also reference it by the alias like this:

nvm use default

Let’s see how to remove Node.js on Debian 11.

Remove Node.js on Debian 11

To remove Node.js versions installed from the default Debian repository or from the PPA, you can use the following command:

sudo apt remove nodejs

This command will remove the package and the configuration files.

To remove a version of Node.js that you have enabled with NVM, first, you need to check the currently active version with the following command:

nvm current

If the version you want to remove is the currently active version, first, you must deactivate the nvm to enable your changes:

nvm deactivate

Then, you can remove it with the following command:

nvm uninstall node_version

If the version you are targeting is not the current active version, you just can use the above command to remove it.

Conclusion

At this point, you learn to install Node with different versions on your Debian 11 server. Also, you can easily remove it from your server.

Hope you enjoy this article about How To Install Node.js on Debian 11.

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!