DebianDebian Based

How To Install Node.js on Debian 12

Install Node.js on Debian 12

In this tutorial, we will show you how to install Node.js on Debian 12. For those of you who didn’t know, Node.js, a powerful and versatile JavaScript runtime environment, has revolutionized modern web development, enabling developers to create scalable and efficient applications.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you step-by-step install Node.js on a Debian 12 (Bookworm).


  • A server running one of the following operating systems: Debian 12 (Bookworm).
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for Node.js.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Node.js on Debian 12 Bookworm

Step 1. Before we install any software, it’s important to make sure your system is up to date by running the following apt commands in the terminal:

sudo apt update
sudo apt install build-essential curl gcc g++ make

This command will refresh the repository, allowing you to install the latest versions of software packages.

Step 2. Installing Node.js on Debian 12.

Node.js versions provided by the official Debian repositories might be outdated. To install the latest Node.js release, we’ll use the NodeSource repository. Execute the following commands to add the repository:

curl -fsSL | sudo -E bash -

Now that we’ve added the NodeSource repository, we can install Node.js using the package manager:

sudo apt install nodejs

To confirm the successful installation of Node.js, check its version:

node -v

If you work on multiple projects with different Node.js version requirements, it’s wise to use Node Version Manager (NVM). With NVM, you can easily switch between Node.js versions. Execute the following command to install NVM:

curl -o- | bash

Close and reopen your terminal to start using NVM, then install a specific Node.js version:

nvm install 16.4.0

Double-check the installed Node.js version to ensure everything is working as expected:

node -v

Step 3. Running a Sample Node.js Application.

Let’s run a simple example to confirm that Node.js is up and running. Create a new file named “hello.js” and add the following code:

console.log("Hello, Node.js!");

Save the file, then run the application using the Node.js command:

node hello.js

The console should display “Hello, Node.js!” if everything is in order.

Step 4. Troubleshooting Tips.

  • Permission Issues: If you encounter permission errors during installation or while running Node.js applications, avoid using the “sudo” command unnecessarily. Instead, consider changing the ownership of the directory where you plan to run your applications:
sudo chown -R $USER:$(id -gn $USER) /path/to/your/project
  • Node.js Not Found: If the “node” command is not recognized, ensure that the Node.js binary path is added to your system’s PATH environment variable. Add the following line to your “/.bashrc" or "/.bash_profile" file:
export PATH=$PATH:/usr/bin/node

Remember to keep your Node.js environment up to date and explore the vast resources available to unleash the true potential of this remarkable technology.

Congratulations! You have successfully installed Node.js. Thanks for using this tutorial to install Node.js on Debian 12 Bookworm. For additional help or useful information, we recommend you check the official Node.js website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!
Back to top button