Node.js” is a powerful and open-source runtime environment for Javascript that permits you to employ the Javascript as both, the front-end and back-end. It is well-known for its quickness, extensibility, and a large ecosystem of different libraries. It is currently deployed in web applications and API’s.

It is not pre-installed on Debian 12 and to install it, you must follow certain steps. This guide enables you to install it on Debian 12.

How to Install “Node.js” on Debian 12

You can install the “Node.js” that comes bundled with “NVM” via the following methods:

  • Using the Default Repositories.
  • Using the NodeSource PPA Repository.
  • Using the NVM.

Method 1: Using the Default Repositories

“Node.js” is officially available in the default repositories and you can install it via the traditional “apt” command, as seen below:

sudo apt install nodejs npm -y

To verify the installation of “Node.js” on Debian 12, run the below command:

nodejs --version

You can verify the installation of “npm” as well, via the following command:

npm --version

Bonus Tip: How to Install the “Node.js” LTS Version on Debian 12

The “LTS” version of “Node.js” is focused more towards the stability of any application that is run. The “LTS” stands for “Long Term Support” and is maintained using the latest security patches. To install the “Node.js” LTS version, run:

nvm install --lts

Bonus Tip: How to Remove “Node.js” Installed From the Default Repositories in Debian 12

If you have installed the “Node.js” using the default repositories in Debian 12, run the following command to remove it:

sudo apt remove nodejs npm -y

Method 2: Using the NodeSource PPA Repository

You can install the “Node.js” using the “NodeSource PPA Repository” as well. Utilizing this approach, you can download/install the newest version from the specified version. Below is a command to install the newest version from the “20” series of the “Node.js” on Debian 12:

sudo curl -fsSL | sudo -E bash - && sudo apt install nodejs -y

To verify the “Node.js” and “npm” installation, execute the below commands:

node -v
npm -v

Additionally, you can always install the “Node.js” newest version (21.x as of this writing) on Debian 12 via the following command:

curl -fsSL | sudo -E bash - &&
sudo apt install -y nodejs

To check the current version of “Node.js” and “npm”, execute the following command:

node -v
npm -v

Bonus Tip: How to Uninstall/Remove the “Node.js” Installed Via the NodeSource PPA Repository

To uninstall the “Node.js” and remove its repository (NodeSource PPA), execute the below-mentioned command:

sudo apt purge nodejs && sudo rm -r /etc/apt/sources.list.d/nodesource.list

Method 3: Using the “NVM”

If you want to install “NVM”, “Node.js” is automatically installed with it. To trigger the installation of the newest  “NVM” and “Node.js” versions, follow these steps:

Step 1: Download the “NVM” Installation Script

The installation script of the “NVM” is hosted on one of GitHub’s domains. To download it, run:

curl | bash

Step 2: List the Available “NVM” Versions

You can specify which version of “NVM” you want to install from a list. To view the list of the “NVM” versions, use the below mentioned command:

nvm ls-remote

Step 3: Install “Node.js” Via “NVM”

Now, for installing the “Node.js” via the “NVM” run the below command and replace the version (v21.6.1 in this case):

nvm install v21.6.1

Step 4: Switch/Set the Default “NVM” Version (Optional)

To use or switch with a specified version of “Node.js” in the current session based on your preferences (21.6.1 in this case) run the following command:

nvm use v21.6.1

To set the above as the “Node.js” default version, execute the below command:

nvm alias default v21.6.1

Bonus Tip: How to Uninstall/Remove the “Node.js” Installed Using the “NVM”

Run the below command to uninstall the “Node.js” version installed using the “NVM”; however, you must know the version you have installed:

nvm uninstall v21.6.1

Final Words

To install the newest public version of “Node.js” on Debian 12, use the default repositories and run the command “sudo apt install nodejs npm”. Additionally, you can install the “Node.js” on Debian 12 via the “NodeSource PPA Repository”.

The recommended method to install the “Node.js” is through the “NVM” as it lets you select the version that suits what you require. This guide has shed light on the methods for installing the “Node.js on Debian 12”.