Share your love
Set up Node.js LTS on Debian 12 Bookworm
This tutorial will show you to Set up and Install Node.js LTS on Debian 12 Bookworm. Node.js is a free and open-source environment for building fast and scalable server-side and networking applications. You can follow this guide to install Node.js using APT, PPA, and NVM on Debian 12.
Set up Node.js LTS on Debian 12 Bookworm
To complete this guide, you must have access to your server as a non-root user with sudo privileges. For this purpose, you can visit the Initial Server Setup with Debian 12 Bookworm.
Step 1 – Install Default Node.js with APT on Debian 12
Debian 12 ships with Node.js 18 LTS. You can easily install it on your server by using the APT package manager. First, run the system update with the command below:
sudo apt update
Then, use the command below to install Node.js on Debian 12:
sudo apt install nodejs
Verify your Node.js installation by checking its version:
node -v
Output
v18.13.0
Install NPM on Debian 12
Also, you need to install the npm (Node.js Package Manager) with the following command:
sudo apt install npm
Check its version:
npm -v
Output
9.2.0
Step 2 – Install Node.js LTS from PPA Repository on Debian 12
To install a different version of Node.js, you can use a PPA (personal package archive) maintained by NodeSource. These PPAs have more versions of Node.js available than the official Debian repositories.
To download the installation script for your preferred version, you can use the following curl command:
Here we download the Node.js 20 the upcoming LTS version.
# cd ~
# sudo curl -sL https://deb.nodesource.com/setup_20.x -o nodesource_setup.sh
When your download is completed, run your installation script:
sudo bash nodesource_setup.sh
The PPA will be added to your configuration and your local package cache will be updated automatically. You can now install the Node.js package with the following command:
sudo apt install nodejs
Verify your Node.js installation on Debian 12 with the command below:
node -v
Output
v20.5.0
Note: With this method, your NPM will be installed during the Node.js installation.
You can verify your NPM by checking its version:
Output
9.8.0
Step 3 – Install Node.js LTS with NVM on Debian 12
The Node Version Manager (NVM) is another way that you can use to install and maintain many different independent versions of Node.js, and their associated Node packages, at the same time.
First, download and install the latest NVM installer script from GitHub with the command below:
sudo wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh | sudo bash
Next, source your .bashrc file with the command below:
source ~/.bashrc
To check which versions of Node are available, run the following command:
nvm list-remote
Output
v18.17.0 (Latest LTS: Hydrogen)
v19.0.0
v19.0.1
v19.1.0
...
v19.8.1
v19.9.0
v20.0.0
...
v20.4.0
v20.5.0
...
For example, to get v18.17.0 LTS, you can use the command below on Debian 12:
nvm install v18.17.0
Now you can see the different versions you have installed with the following command:
nvm list
Output
-> v18.17.0
system
default -> v18.17.0
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v18.17.0) (default)
stable -> 18.17 (-> v18.17.0) (default)
lts/* -> lts/hydrogen (-> v18.17.0)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.12 (-> N/A)
lts/fermium -> v14.21.3 (-> N/A)
lts/gallium -> v16.20.1 (-> N/A)
lts/hydrogen -> v18.17.0
Note: If you also have a version of Node.js installed through apt
, you may see an system
entry here. You can always activate the system-installed version of Node using nvm use system
.
Conclusion
At this point, you have learned to Set up and Install Node.js LTS on Debian 12 Bookworm. You can easily install the default Nod.js and the LTS versions by using APT, PPA, and NVM on your server.
Hope you enjoy using it. You may like these articles too: