Node.js is an open-source, cross-platform runtime environment that provides a platform for JavaScript, primarily used in web servers and APIs. Furthermore, its event-driven architecture and asynchronous programming enable it to handle a large volume of concurrent requests. Debian, on the other hand, is also a stable Linux distribution that offers a strong foundation for deploying and building web and other server-side applications. This blog post will extensively discuss all the possible ways to install Node.js on Debian.
6- Ways to Install Node.js on Debian
Node.js provides a faster development cycle and reduces the context switch between different languages. Further, it can be used for both back-end and front-end development, thus simplifying the development for full-stack developers. On Debian, there are 6 different ways to install Node.js on Debian which this guide will explain.
1: Through Debian apt Package Manager
To install Node.js on Debian using the apt package manager is one of the simplest methods. If you are willing to use its older version, run the following command:
sudo apt install nodejs -y
To validate the Node.js Installation on Debian, check its version by executing the command below:
node -vHere, in the image below, it can be seen that the older version of Node.js is installed through apt:

Further, you will need a node package manager to install JavaScript packages on Debian so execute:
sudo apt install npm -y
Just to verify the node version manager(npm) installation, check its version by running:
npm -v
2: Through Node.js Deb Repository
The deb repository of Node.js comes with version 20 of Node.js, so simply download and execute it in the bash shell by using the following command:
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo bash -The repository will be saved in the sources.list the directory of Debian:

Next, use the Debian default repository to install Node.js on Debian:
sudo apt-get install -y nodejs
To validate the Node.js installation on Debian, check its version by executing the following command:
node -vHere in the image below, you can see that the node version 20 is installed:

3: Through Node Version Manager (NVM)
To install multiple versions of Node.js on Debian 12, the best way is to use the Node Version Manager. Using this node version manager, you can also switch between Node.js versions. First, install the Node Version Manager on Debian using the GitHub bash file for NVM:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bashThis will create a hidden NVM folder on Debian, which you can remove if you want to uninstall NVM after deactivating it:

Next, restart your terminal or execute the command below to add the NVM script to the path:
source ~/.profile
As previously mentioned, NVM comes with all the versions of Node.js, so to list all of them, execute the below command:
nvm ls-remote
Currently, the latest version of Node.js is 22.3.0 in NVM to install Node.js on Debian using NVM execute the below command:
nvm install [desired-nodejs-version]Here, I have installed the latest version of Node.js on Debian:

4: Through Node.js Pre-built Binaries
Another way to install Node.js on Debian is by using its pre-built binaries. This method doesn’t require any installation process. Just extract the file and execute it. First, visit the download page of Node.js and then select the Prebuilt Binaries option. Afterward, select the desired Node.js version, then select the Linux operating system along with its architecture. Next, click on the download option:

Once the file is downloaded, extract the contents of the file by using the command below. Further edit this command as it will vary based on the version of Node.js:
sudo tar -xvf node-v22.3.0-linux-x64.tar.xz
Next, move to the bin directory of the extracted folder and execute the node file. This will launch Node.js on Debian:
./node
5: Through Node.js Source Code
The fifth method to install Node.js on Debian is by compiling the source file, which can be downloaded from the Node.js official website. Before downloading the source file, select the Node.js version and then click on the Download option:

The next thing to do is to extract the source file of Node.js by using the tar utility along with xvzf flags:
sudo tar xvzf node-v22.3.0.tar.gz
Now move to the extracted directory of the Node.js source file on Debian. Here, you will find a file named configure, which will be used to check all the necessary packages for installing Node.js:

Next, execute the configuration file in the source code of Node.js
./configure
Now create the Makefile for Node.js that specifies the dependencies required for a successful installation, and define rules that specify the commands to execute for the installation target.
make -j4This step will take more than an hour, but the estimated time is purely dependent on the system resources:

Next, install Node.js on Debian using the created make file; again, this step will also take an hour to complete roughly:
make install
6: Through Snap Package Manager
The last method to install Node.js on Debian is using the Snap package manager by executing:
sudo snap install node --channel=22/stable --classic
Next, list all the Debian applications installed via the Snap package manager to validate the installation of Node.js on Debian 12:
sudo snap list
How to Switch Node.js Versions Using NVM in Debian
Using the Node Version Manager, you can not only install multiple Node.js versions but can also switch between them on Debian. Like, you can also set different versions for the default and current use. Moreover, you can also switch between Node.js versions depending on your needs. Firstly, it is better to know which Node.js versions are available, for that list all Node.js versions available in the Node Version Manager:
nvm ls-remote
Next, you can list all the installed versions of nodejs on Debian 12 by executing the below command:
nvm lsHere in the image below you can see that the current version of Node.js in use is 18 whereas the default version set for Node.js is 22.3.0:

To use a different version then use the below syntax for switching to the desired version:
nvm use [deired-nodejs-version]Here, for instance, I have switched my current version of Node.js on Debian from 18 to 22, and in the image below you can see that version 18.20.3 is the current version in use switched to version 22:

If you want to set any desired version as default for nodejs on Debian, then use the below syntax:
nvm alias default [desired-nodejs-version]Here, I have changed my default node.js version from 22.3.0 to 18.20.3

Note: Instead of using the version number for Node.js installation on Debian, you can also use the respective version name if installing through the Node Version Manager.
Conclusion
To install Node.js on Debian, there are six ways which include using the apt package manager, Snap app installer, Node.js Deb repository, node version manager, Node.js prebuilt binaries, and Node.js source code. The recommended method for Node.js installation on Debian 12 is using the Node Version Manager. This is because one can select from a wide range of available versions and can also have multiple Node.js versions installed, which can also be switched.
