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.

#!/bin/bash

# Set the version of node we wish to install
NODE_MAJOR=18

# 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 https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key \
  | 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] https://deb.nodesource.com/node_$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 https://deb.nodesource.com/setup_18.x | 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.

References

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