Tutorials  /  JavaScript

Install Node.js and NPM on Ubuntu 22.04 – Complete Setup with NVM

Ccentron Redaktion · October 2025 ·5 min read ·JavaScript, Tutorial

Node.js is a cross-platform, open-source JavaScript runtime environment used for building scalable server-side applications. NPM serves as the package manager that handles dependencies, libraries, and scripts, making it easier to develop and manage server-based JavaScript projects.

This guide explains how to install Node.js and NPM on Ubuntu 22.04 using the NodeSource PPA and how to manage multiple Node.js versions through NVM (Node Version Manager).

Prerequisites

Before you begin, make sure you have the following:

  • An Ubuntu 22.04 server.
  • SSH access as a non-root user with sudo privileges.
  • An updated package index on your Ubuntu server.
VM

Matching infrastructure at centron

Node applications need somewhere to run: ccloud³ VMs with full root access from €3.12 per month – or as a managed server if you would rather not run it yourself. Rent a cloud server →

Choose a Node.js Version

When selecting which version of Node.js to install, consider these points:

  • Latest Release: Contains the most recent features and improvements—ideal for development or projects requiring the latest capabilities.
  • LTS (Long-Term Support): A stable version recommended for production environments.

Important factors include:

  • Stability: Use the latest LTS for reliability in production.
  • Features: Choose the latest release for cutting-edge functionality.

Install Node.js

The Ubuntu 22.04 APT repositories may not include the latest Node.js release. To install the most up-to-date version, add the NodeSource PPA for your desired Node.js branch.

Update the Package Index

Console
$ sudo apt update

Download the NodeSource Setup Script

Download the installation script for your chosen Node.js version. For example, to install Node.js 22.x:

Console
$ curl -fsSL https://deb.nodesource.com/setup_22.x -o nodesource_setup.sh

Visit the official NodeSource documentation to confirm which versions are available.

Run the Setup Script

Console
$ sudo -E bash nodesource_setup.sh

Install Node.js and NPM

Console
$ sudo apt-get install -y nodejs npm

Check Node.js Version

Console
$ node -v

Expected output:

v22.14.0

Check NPM Version

Console
$ npm -v

Expected output:

10.9.2

Test the Installation

Create a New Project Directory

Console
$ mkdir example-site

Navigate to the Project Directory

Console
$ cd example-site

Initialize a Node.js Project

Console
$ npm init -y

Install Express Framework

Console
$ npm install express

Create an Application File

Console
$ nano index.js

Add the Following Code

JavaScript
const express = require('express')
const app = express()
const port = 3000

app.get('/', (req, res) => {
    res.send('Hello World! Greetings from centron')
})

app.listen(port, () => {
    console.log(`Example app listening on port ${port}`)
})

This example creates an Express web server that responds with “Hello World! Greetings from centron” when accessed at port 3000.

Allow Port 3000 Through the Firewall

Console
$ sudo ufw allow 3000

Reload the Firewall

Console
$ sudo ufw reload

Run the Application

Console
$ node index.js

Access your app in the browser using your server’s IP and port 3000:

http://<server-ip>:3000

Install Multiple Versions with NVM

NVM (Node Version Manager) enables you to install and manage multiple Node.js versions on your system. Follow these steps to use NVM for version control.

Download the NVM Installation Script

Console
$ curl -O https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh

Check the latest NVM version on the official documentation before proceeding.

Install NVM

Console
$ bash install.sh

Reload the Environment

Console
$ source ~/.profile

List Available Node.js Versions

Console
$ nvm ls-remote

Example output:

v20.13.1   (LTS: Iron)
v20.14.0   (Latest LTS: Iron)
v21.0.0
v21.6.0
v22.0.0
v22.2.0

Install a Specific Version

Console
$ nvm install 20

List Installed Versions

Console
$ nvm ls

Example output:

v20.14.0
-> v21.7.3
default -> 20 (-> v20.14.0)
node -> stable (-> v21.7.3) (default)
lts/* -> lts/iron (-> v20.14.0)

Switch to a Specific Version

Console
$ nvm use 20

Output:

Now using node v20.14.0 (npm v10.7.0)

Check Node.js and NPM Versions

Console
$ node -v
$ npm -v

Set a Default Node.js Version

Console
$ nvm alias default 20

Conclusion

In this tutorial, you installed Node.js and NPM on Ubuntu 22.04 using NodeSource. You also learned how to use NVM to manage multiple Node.js versions, enabling a flexible development environment for server-side JavaScript applications.

Jetzt 200 € Guthaben sichern

Testen Sie Ihr Setup auf ccloud³

Registrieren Sie sich in der ccloud³ und erhalten Sie 200 € Startguthaben für Ihr Projekt – z. B. für eine PostgreSQL-VM mit automatischen Backups.

centron Redaktion Technische Redaktion

Das Redaktionsteam von centron schreibt Anleitungen aus dem Betriebsalltag: getestet auf unserer eigenen Plattform, betrieben im Rechenzentrum in Hallstadt bei Bamberg.

Kategorie JavaScript
Teilen
Noch offene Fragen?

Our team will help you with your specific setup - in German or English, by people who run the platform themselves.

War dieses Tutorial hilfreich?

Your answer is stored anonymously and helps us improve our tutorials.

Kommentare

No comments yet - be the first to ask a question about this tutorial.

Sign in to comment

Comments are open to centron customers. Sign in to your account to ask a question about this tutorial.

Weiterlesen

Das könnte Sie auch interessieren

Jetzt kostenlos anfangen

Melden Sie sich an und erhalten Sie in den ersten 60 Tagen ein Guthaben von 200 € bei centron.

Dieses Werbeangebot gilt nur für neue Konten. Angebot ausschließlich für Gewerbetreibende.

Jetzt loslegen Sales kontaktieren