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.
non-root sudo useror 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 https://deb.nodesource.com/setup_14.x | 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:
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- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | 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:
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:
Save the file, then run the application using the Node.js command:
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
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.