Are you looking for a simple guide on how to install Node.js on Debian 12? This tutorial will walk you through installing both Node.js and NPM on your Debian 12 server.
Node.js is a runtime for JavaScript that enables you to run JavaScript code outside of a web browser. It is mainly used for scalable backend web applications and networking tools.
How To Install Node.js on Debian 12
To install Node.js on Debian 12, you have two options. The first one uses apt
to install the nodejs
package from Debian’s default software repository. The second option involves using Node.js binary distributions provided by NodeSource, which allows you to install different and more recent stable versions of Node.js.
I will walk you through both options to install Node.js on your Debian server, and then you can choose whichever one you prefer.
Installing Node.js on Debian - Prerequisites
- Basic knowledge of the Linux command line.
- An Debian 12 server with a non-root user with
sudo
privileges. You can get affordable, and powerful Debian servers from our website, and you can check out our How to access your server using SSH guide to learn how to access your server and create asudo
user.
Updating the Package Cache and Installing Build Tools
Start by updating the packages in the package manager cache to the latest available versions using the following command:
sudo apt update
Before you install Node.js, it is recommended that you install build tools to compile and install native add-ons from the Node.js package manager:
sudo apt install -y build-essential
Option 1: Installing Node.js on Debian From the Default Repositories
For the simplest way to install Node.js on Debian, you can use apt
to install the default Node.js version that is available in the default Debian repositories. However, note that this version is an LTS (long-term support) release, which is often outdated, although it has a long support period.
To install the nodejs
package, use the following command:
sudo apt install -y nodejs
If you are asked to restart any services, press ENTER
.
Once the installation is finished, you can check the Node.js version to ensure it was successfully installed:
node -v
You should receive an output that is similar to the following:
Next, install the npm
package manager for managing Node.js packages and modules:
sudo apt install -y npm
With this, you should now have a fully functional Node.js JavaScript runtime and a Node.js package manager on your Debian server. However, the Node.js version is a bit outdated, so if you'd like to install a different version or the most recent one, you need to go with the second option below.
Option 2: Installing Node.js on Debian with NodeSource Node.js Binary Distributions
To install a different version of Node.js on Debian, you can use the NodeSource Node.js Binary Distributions using a simple command.
Before you continue, you need to first install curl
:
sudo apt install -y curl
Installing Node.js v21.x on Debian
To install Node.js v21.x, use the following command to setup the PPA repository:
curl -fsSL https://deb.nodesource.com/setup_21.x | sudo -E bash - &&\
Then install the nodejs
package:
sudo apt install -y nodejs
If you are asked to restart any services, press ENTER
.
Once the installation is finished, you can check the Node.js version to ensure it was successfully installed:
node -v
You should receive an output that is similar to the following:
Installing Node.js v20.x on Debian
To install Node.js v20.x, use the following command to setup the PPA repository:
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - &&\
Then install the nodejs
package:
sudo apt install -y nodejs
If you are asked to restart any services, press ENTER
.
Once the installation is finished, you can check the Node.js version to ensure it was successfully installed:
node -v
You should receive an output that is similar to the following:
Installing Node.js v19.x on Debian
To install Node.js v19.x, use the following command to setup the PPA repository:
curl -fsSL https://deb.nodesource.com/setup_19.x | sudo -E bash -
Then install the nodejs
package:
sudo apt install -y nodejs
If you are asked to restart any services, press ENTER
.
Once the installation is finished, you can check the Node.js version to ensure it was successfully installed:
node -v
You should receive an output that is similar to the following:
Installing Node.js v18.x on Debian
To install Node.js v18.x, use the following command to setup the PPA repository:
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
Then install the nodejs
package:
sudo apt install -y nodejs
If you are asked to restart any services, press ENTER
.
Once the installation is finished, you can check the Node.js version to ensure it was successfully installed:
node -v
You should receive an output that is similar to the following:
Installing Node.js v16.x on Debian
To install Node.js v16.x, use the following command to setup the PPA repository:
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
Then install the nodejs
package:
sudo apt install -y nodejs
If you are asked to restart any services, press ENTER
.
Once the installation is finished, you can check the Node.js version to ensure it was successfully installed:
node -v
You should receive an output that is similar to the following:
Installing Node.js v14.x on Debian
To install Node.js v14.x, use the following command to setup the PPA repository:
curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
Then install the nodejs
package:
sudo apt install -y nodejs
If you are asked to restart any services, press ENTER
.
Once the installation is finished, you can check the Node.js version to ensure it was successfully installed:
node -v
You should receive an output that is similar to the following:
Congrats
You now have your preferred version of Node.js installed on your Debian server, and you can now use JavaScript with Node.js to create applications for the web, write mobile and desktop apps, and create networking tools, and build many other packages for different purposes. To learn more about Node.js, checkout the official website.
A note about tutorials: We encourage our users to try out tutorials, but they aren't fully supported by our team—we can't always provide support when things go wrong. Be sure to check which OS and version it was tested with before you proceed.
If you want a fully managed experience, with dedicated support for any application you might want to run, contact us for more information.