How to install Node.js in Debian 12

Endrit Qerreti

Endrit Qerreti

In this tutorial, you will learn how to install Node.js on Debian 12.

Node.js can be used on any Linux distro, including Debian 12.

In this tutorial, we'll be installing the latest version of Node.js, via the official Node.js repository, which allows Linux users to download any version of Node.js such as : Node 16, Node 18, Node 20 and Node 21.

To install Node.js on Debian 12, simply follow the steps below.

Install Node.js on Debian

There are many ways to install Node.js on Debian 12. However, in this tutorial, like we said, we are going to use the official Node.js deb repository to install Node.js in our Debian machine.

Step 1 - Update your Debian machine

First thing that you need to do before installing Node.js, is to update your machine, in order to make sure that you won't have any issues during the installation process.

To update your Debian machine, you can use apt.

sudo apt update

Step 2 - Install the required packages

Now that your Debian 12 machine is updated, you need to install the required packages that we'll be using for this tutorial to download and setup Node.js repository.

To do so, simply run the following.

sudo apt install curl gnupg ca-certificates -y

Step 3 - Add Node.js GPG Key

Next, proceed to import Node.js GPG key in on your Debian 12 machine. Importing the GPG key is very easy, and it can be done easily by using curl.

curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg

Step 4 - Create Node.js Repository

Before creating the repository file for Node.js in your Debian 12 machine, you need first to choose Node.js version that you want to download.

To do so, simply run the command below.

NODE_MAJOR=21

At the time of writing this tutorial, v21.4.0 is the latest version of Node.js.

Once you've chosen the latest version of Node.js, proceed to create Node.js repository.

To do so, run the following.

echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list

Step 5 - Install Node.js

Now that Node.js repository is added on your Debian 12 machine, proceed to update the package index of your machine, so that you can use the newly added repository.

sudo apt update

💡
Note: If you get the error "repository doesn't support architecture 'i386', you can easily fix it by following our tutorial here.

Once package index is updated, all you have to now is run the command below to install Node.js

sudo apt install nodejs

Step 6 - Check Node.js Version

Node.js is now installed on your system.

In this tutorial, we installed the latest version of Node.js v21.4.0, to verify that the latest version was installed, simply check Node.js version by running the command below.

node --version

Conclusion

In this tutorial, you learned how to install the latest version of Node.js on Debian 12, via the official Node.js deb repository.