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.

Follow the rest of the article on the Orcacore website to set up Node.js on Debian 11 by using different methods, including APT repository, PPA repository, and using NVM.

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.

Method 1. Install Node.js with APT Repository

Node.js package is available by default in the Debian 11 repository, but it may not be in the latest version. 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 -y

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

Method 2. Install Node JS from Node Source

You can install Node.js from a PPA (personal package archive) maintained by NodeSource. NodeSource has PPAs available for Node versions. First, install the curl command:

sudo apt install curl -y

Use the curl command to get the installation script for your preferred Node.js version. At the current time, the LTS version is 22.

sudo curl -sL https://deb.nodesource.com/setup_22.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.

Install Node.js on Debian 11 From NodeSource

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 -y

You can verify the installation with the following command:

node -v
Output
v22.18.0

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
Output
10.9.3

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 -y

Method 3. 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:

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

Then run the NVM installation script with the following command:

sudo 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:

sudo 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:

list the available Node.js versions with NVM

As you can see, the current LTS version is v22.18.0. You can install it with the following command:

nvm install 22.18.0

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

node -v

Your output should be similar to this:

Output
v22.18.0

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 by default, you can use the following command:

nvm alias default 22.18.0

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 From 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 -y

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 can just use the above command to remove it.

Conclusion

At this point, you have learned to install Node in different ways 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. Please subscribe to us on Facebook, X, and YouTube.

You may also like to read the following articles:

Upgrade From Debian 10 Buster To Debian 11 Bullseye

Upgrade From Debian 12 To Debian 13 Trixie

How To Enable NTP in Debian 13?

Share your love

Stay informed and not overwhelmed, subscribe now!