How to Install Node.js and npm on Linux (LTS, nvm and Production Tips)

install nodejs linux npm - custom-node-featured.png

Developers search for install Node.js Linux constantly because the Node version in default distro repos is often years old. For APIs and Next.js backends on a VPS you want a current LTS build and a repeatable way to update.

Pair this with Nginx as reverse proxy and
UFW so only ports 80/443 are public.

What You Are Installing

Node.js is the runtime; npm is the package manager bundled with official Node builds. Production servers usually run one LTS major version per machine unless you use nvm per deploy user.

Node and npm
runtime + packages

Install LTS from NodeSource (Server Default)

On Ubuntu/Debian, NodeSource setup scripts install maintained packages. On Alma/Rocky, use the equivalent NodeSource or module stream — always check node -v after install.

bashDebian/Ubuntu example (check nodesource.com for current LTS)
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install -y nodejs
node -v && npm -v
LTS install
avoid stale apt node

npm init and Local Dependencies

Run npm install inside your project directory. Commit package-lock.json for reproducible builds.

bashnew project
mkdir myapi && cd myapi
npm init -y
npm install express
npm in project
package.json

Global CLI Tools

Install CLIs globally only when needed; prefer npx for one-off commands to avoid version conflicts.

bashexample
npx create-next-app@latest myapp
global vs local
npx

Run as a Service

Use systemd for simple Node apps or PM2 for cluster mode. Bind the app to 127.0.0.1 and let Nginx handle TLS.

TipSee custom systemd units for a minimal service file.
production process
systemd or PM2

Firewall and Exposure

Do not expose port 3000 to the internet unless you mean to. Proxy through Nginx on 443.

UFW
proxy only

Verify

Hit the app locally, then through the proxy.

bashlocal test
curl -s http://127.0.0.1:3000/health
checks
curl and logs

Quick Reference

  • Use current LTS — verify with node -v
  • npm install in project dir; lockfile in git
  • Bind localhost; Nginx on 443

Related tutorials

Diagrams are original illustrations by Gnome IT Solutions. Tutorial text © Gnome IT Solutions.