How to Install Node.js on Debian 12

Node.js is an open source server environment. Node.js allows you to run JavaScript on the server.

Login to the Debian 12 server.

Install via APT Package Manager

Install stable nodejs from the Debian repository by running the following command.

apt install nodejs

Output:

root@vps:~# apt install nodejs
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libc-ares2 libnode108 node-acorn node-busboy node-cjs-module-lexer node-undici node-xtend nodejs-doc
Suggested packages:
  npm
The following NEW packages will be installed:
  libc-ares2 libnode108 node-acorn node-busboy node-cjs-module-lexer node-undici node-xtend nodejs nodejs-doc  

Then check the version of the nodejs once the installation is done.

node --version

Output:

root@vps:~# node --version
v18.13.0
root@vps:~#

Installing a different version of Node.js from source

For this, we will take help of nvm manager. To get the latest version of the nvm, visit their github repository.

Download the install.sh script and run it using the below command,

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash

Output:

root@vps:~# wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
=> Downloading nvm as script to '/root/.nvm'

=> Appending nvm source string to /root/.bashrc
=> Appending bash_completion source string to /root/.bashrc
=> Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
root@vps:~# 

Update your shell ~/.profile by running following command

source ~/.profile

Next, Check if NVM is installed or not by checking for its version.

nvm --version

Output:

root@vps:~# nvm --version
0.39.3
root@vps:~#

List out all available Node.js versions. you can see all Node.js versions from the first version to the latest version.

nvm ls-remote

Output:

root@vps:~# nvm ls-remote
        ...
        v0.1.20
        v0.1.21
        v0.1.22
        v0.1.23
       v18.14.2   (LTS: Hydrogen)
       v18.15.0   (LTS: Hydrogen)
       v18.16.0   (Latest LTS: Hydrogen)
        v19.0.0
        v19.0.1
        v19.1.0
        v19.2.0
        ...

        v19.9.0
        v20.0.0
        v20.1.0
        v20.2.0
        v20.3.0

Now install Node.js with the version you want by running "nvm install" command.

eg: Here 20.3.0 (the very latest version of node.js avaiable at the time of writing this article)

nvm install v20.3.0

Output:

root@vps:~# nvm install v20.3.0
Downloading and installing node v20.3.0...
Downloading https://nodejs.org/dist/v20.3.0/node-v20.3.0-linux-x64.tar.xz...
--2023-06-20 20:02:44--  https://nodejs.org/dist/v20.3.0/node-v20.3.0-linux-x64.tar.xz
Resolving nodejs.org (nodejs.org)... 104.20.23.46, 104.20.22.46, 2606:4700:10::6814:162e, ...
Connecting to nodejs.org (nodejs.org)|104.20.23.46|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 25059080 (24M) [application/x-xz]
Saving to: ‘/root/.nvm/.cache/bin/node-v20.3.0-linux-x64/node-v20.3.0-linux-x64.tar.xz’

/root/.nvm/.cache/bin/nod 100%[====================================>]  23.90M  76.4MB/s    in 0.3s

2023-06-20 20:02:45 (76.4 MB/s) - ‘/root/.nvm/.cache/bin/node-v20.3.0-linux-x64/node-v20.3.0-linux-x64.tar.xz’ saved [25059080/25059080]

Computing checksum with sha256sum
Checksums matched!
Now using node v20.3.0 (npm v9.6.7)

Now check the version of the nodejs once the installation is done.

node -v

Output:

root@vps:~# node -v
v20.3.0

This concludes the topic of installing Node.js on a Debian 12 system. Using two different ways, apt and nvm package managers.


CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME for 10% off!

1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month

Available Locations: LAX | MIA | ATL | FRA | AMS