Knowledgebase

Find frequently asked questions and setup guides by searching or by browsing the categories.

Three Ways to Install Node.js

RouteSuits
Ubuntu packageApps that work with the release's version
NodeSourceOne current LTS for system services
nvmOne user, several versions

Install Node.js only one way on a server; two copies lead to confusion over which one runs. The Ubuntu and NodeSource steps work the same on Debian.

Option 1: Ubuntu's Own Package

sudo apt update
apt-cache policy nodejs
sudo apt install nodejs npm
node -v

apt-cache policy shows the version before you install. Ubuntu keeps one Node.js line for the life of each release, so it is often older than the current LTS: Ubuntu 24.04 ships Node.js 18, a line the Node.js project no longer supports, and Ubuntu 26.04 ships Node.js 22. Check that your application supports that version.

Option 2: The NodeSource Repository

NodeSource publishes packages for each Node.js major version. Adding its repository means trusting its publisher with root on the server. Never pipe the setup script into a shell; download it, read it, then run it:

curl -fsSLo nodesource_setup.sh https://deb.nodesource.com/setup_26.x
less nodesource_setup.sh
sudo bash nodesource_setup.sh
sudo apt install nodejs
node -v

26 is an example major version, the Active LTS line in November 2026. The release page on nodejs.org shows which lines are in LTS, and the NodeSource project's documentation lists the majors it supports. The script adds the signing key and the repository entry. The NodeSource nodejs package includes npm, so do not install Ubuntu's npm package next to it; remove Ubuntu's nodejs first if it is installed.

Option 3: nvm for One User

nvm installs Node.js inside one user's home folder, without root. Run it as that user. The install script address contains a release tag. Copy the current address from the nvm project's GitHub README and use it in place of the one below, where vX.Y.Z stands for that tag:

curl -fsSLo install-nvm.sh https://raw.githubusercontent.com/nvm-sh/nvm/vX.Y.Z/install.sh
less install-nvm.sh
bash install-nvm.sh
source ~/.bashrc
nvm install --lts
node -v

Other users, sudo, and systemd do not see this Node.js unless you give them the full path, which includes the version number. That makes nvm a good fit for development and a weaker one for system services.

npm and a First Check

npm -v
node -e "console.log('Node.js works')"

Install global tools with sudo npm install -g pm2 on the first two routes, and without sudo under nvm.

Run the App as a Service

Do not leave the app in an SSH session. Use pm2, or a systemd unit with a dedicated user and Restart=on-failure; see systemd unit files. For a quick test only, nohup keeps a process running after you log out.

Put Nginx in Front

Let the app listen on 127.0.0.1:3000 and let Nginx take the public traffic on ports 80 and 443. In the server block:

location / {
    proxy_pass http://127.0.0.1:3000;
    proxy_http_version 1.1;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
}

Test with sudo nginx -t and reload with sudo systemctl reload nginx. Keep port 3000 closed in the firewall. If Nginx answers with an error page, the app is usually not running; see 503 Service Unavailable.

Upgrading Later

Upgrade Node.js the same way you installed it. The steps for each route are in how to update Node.js.

Was this answer helpful?
Loading...