Tutorials  /  Ubuntu

Install Node.js & NPM on Ubuntu 20.04 with NVM

Ccentron Redaktion · October 2025 ·6 min read ·Ubuntu, Tutorial

Node.js is an open-source, cross-platform JavaScript runtime environment designed for building scalable server-side applications. The Node Package Manager (NPM) is a crucial utility for handling libraries, dependencies, and scripts within a Node.js project. By installing Node.js and NPM on your server, you can leverage JavaScript as a server-side language.

This guide details how to set up Node.js and NPM on Ubuntu 20.04. You will install both Node.js and NPM using the NodeSource PPA and learn how to run multiple versions with NVM (Node Version Manager).

Prerequisites

Before you start, ensure you have the following:

  • An Ubuntu 20.04 server.
  • SSH access as a non-root user with sudo privileges.
  • A fully updated server.
VM

Matching infrastructure at centron

Ubuntu servers without your own hardware: ccloud³ VMs with full root access from €3.12 per month, billed by the hour and ready in seconds. Rent a cloud server →

Choose a Node.js Version

When selecting a Node.js version, consider aspects such as stability, performance, and application compatibility. The supported Node.js release types are:

  • Latest Release: Contains the newest updates, improvements, and features. Best for applications requiring the latest capabilities.
  • LTS Release: A long-term support version that receives critical updates and bug fixes. Recommended for production environments due to reliability and extended maintenance.

Factors to keep in mind:

  • Stability and Support: For production or dependable environments, the latest LTS release is recommended.
  • Feature Requirements: If your project needs the newest features or performance enhancements, opt for the latest release version.

Install Node.js

The default APT repositories in Ubuntu 20.04 might not offer the most recent Node.js version. Use the NodeSource PPA to add the latest repository for your preferred Node.js version.

Update the server package index:

Console
$ sudo apt update

Download the Node.js version 22.x PPA installation script:

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

Refer to the official NodeSource documentation to verify all available Node.js versions.

Run the Node.js setup script:

Console
$ sudo -E bash nodesource_setup.sh

Install Node.js and NPM:

Console
$ sudo apt-get install -y nodejs npm

Check the installed Node.js version:

Console
$ node -v

Output: v22.14.0

Check the installed NPM version:

Console
$ npm -v

Output: 10.9.2

Test the Installation

Create a new project directory, for example:

Console
$ mkdir example-site

Navigate into the directory:

Console
$ cd example-site

Initialize a new Node.js project:

Console
$ npm init -y

Install the Express module:

Console
$ npm install express

Create the application file index.js:

Console
$ nano index.js

Add the following code to the file:

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 Node.js script creates an Express application that listens on port 3000 and returns a "Hello World! Greetings from centron" message.

Allow port 3000 through the firewall:

Console
$ sudo ufw allow 3000

Reload the firewall:

Console
$ sudo ufw reload

Start the Node.js application:

Console
$ node index.js

Now, open a browser and access your application using:

http://<server-ip>:3000

Install Multiple Versions with Node Version Manager (NVM)

NVM (Node Version Manager) is a convenient tool for managing multiple Node.js versions. You can install and switch between different versions as needed. Follow these steps to set up NVM and install the desired Node.js versions.

Download the latest NVM installation script:

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

Check the NVM documentation to ensure you have the latest version.

Run the script to install NVM:

Console
$ bash install.sh

Reload your environment variables:

Console
$ source ~/.profile

List all available Node.js versions:

Console
$ nvm ls-remote

Sample output:

...
v20.13.1   (LTS: Iron)
v20.14.0   (Latest LTS: Iron)
v21.0.0
v21.6.0
v21.6.1
v21.6.2
v21.7.0
v21.7.1
v21.7.2
v21.7.3
v22.0.0
v22.1.0
v22.2.0

Install Node.js version 20:

Console
$ nvm install 20

List installed Node.js versions and verify the default version:

Console
$ nvm ls

Output:

          v20.14.0
   ->      v21.7.3
   default -> 20 (-> v20.14.0)
   iojs -> N/A (default)
   unstable -> N/A (default)
   node -> stable (-> v21.7.3) (default)
   stable -> 21.7 (-> v21.7.3) (default)
   lts/* -> lts/iron (-> v20.14.0)

Activate a specific Node.js version, such as 20:

Console
$ nvm use 20

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

Check the active Node.js version:

Console
$ node -v

Output: v20.14.0

Check the NPM version:

Console
$ npm -v

Output: 10.7.0

Set a specific Node.js version as the default in your environment:

Console
$ nvm alias default 20

Conclusion

You have successfully installed Node.js and NPM on Ubuntu 20.04. With Node Version Manager (NVM), you can seamlessly switch between different Node.js versions to suit your project requirements.

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 Ubuntu
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