Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Install NodeJS

Debian 12 Instructions

The script below has been tested on Debian 12, and will install Node 18. You can simply change the NODE_MAJOR variable if you wish to install a different version of Node, such as Node 20.


# Set the version of node we wish to install

# Add the keyring for the node repository we are going to add later
sudo apt-get update \
  && sudo apt-get install -y ca-certificates curl gnupg \
  && sudo mkdir -p /etc/apt/keyrings \
  && curl -fsSL \
  | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg

# Now add the node repository that we wish to install node from
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg]$NODE_MAJOR.x nodistro main" \
  | sudo tee /etc/apt/sources.list.d/nodesource.list

# Now install the nodeJS package
sudo apt-get update \
  && sudo apt-get install nodejs -y

Original (Outdated) Instructions

Below are the original instructions I used to give, which are now outdated and will not work in the future.

Below are the instructions to install nodejs on a debian based distribution such as Ubuntu.

Ubuntu 18.04 - Native Packages

sudo apt update && \
sudo apt install npm node-gyp nodejs-dev libssl1.0-dev -y

18.x LTS

curl -sL | sudo -E bash - \
  && sudo apt-get install -y nodejs -y

Running the webserver

Add the bin folder to your path, then simply execute:

node [serverFile.js]

This will run node on a single thread. If you have multiple vCPUs then you may wish to run Nginx or Apache as the HTTP handler which calls node.


Last updated: 14th October 2023
First published: 16th August 2018