How to Install Node.js and npm on Ubuntu 26.04

Node.js is an open-source, cross-platform JavaScript runtime built on the V8 engine that enables server-side application development. npm (Node Package Manager) ships with Node.js and provides access to a registry of over two million packages for managing project dependencies, scripts, and build tools.
This article explains how to install Node.js and npm on an Ubuntu 26.04 server using the NodeSource repository, test the installation with a sample Express application, and manage multiple Node.js versions using NVM (Node Version Manager).
Prerequisites
Before you begin, you need to:
- Have access to an Ubuntu 26.04 server instance as a non-root user with sudo privileges.
Install Node.js
The default Ubuntu 26.04 repositories include a Node.js package, but it may not be the latest version. Two installation methods are available: the NodeSource PPA for system-wide installation, or NVM for per-user version management.
The NodeSource PPA provides up-to-date Node.js releases for specific major versions. This method installs Node.js and npm system-wide.
Update the APT package index.
console$ sudo apt update
Download the NodeSource setup script for your desired major version. For example, Node.js 24.x.
console$ curl -fsSL https://deb.nodesource.com/setup_24.x -o nodesource_setup.sh
Refer to the NodeSource distributions page to view all available Node.js versions.
Run the setup script to add the repository.
console$ sudo bash nodesource_setup.sh
Install Node.js and npm.
console$ sudo apt install nodejs -y
Confirm the installed Node.js version.
console$ node -v
Your output should be similar to the one below:
v24.13.0Confirm the installed npm version.
console$ npm -v
Your output should be similar to the one below:
11.6.2
NVM (Node Version Manager) installs Node.js in your user environment without requiring root privileges. It supports installing and switching between multiple Node.js versions side by side.
Download and run the NVM installation script.
console$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
Refer to the NVM GitHub repository for the latest version of the install script.
Reload the shell environment to activate NVM.
console$ source ~/.bashrc
Install a specific Node.js version. For example, the latest LTS release.
console$ nvm install --lts
Or install a specific major version. For example, Node.js 24.
console$ nvm install 24
List all locally installed versions.
console$ nvm ls
Switch to a specific version.
console$ nvm use 24
Set a default version for new terminal sessions.
console$ nvm alias default 24
Confirm the active Node.js version.
console$ node -v
Test the Installation
The following steps create a sample Express web application to verify that Node.js and npm are functioning correctly.
Create a new project directory and navigate into it.
console$ mkdir ~/example-app && cd ~/example-app
Initialize a new Node.js project.
console$ npm init -y
Install the Express framework.
console$ npm install express
Create the application file.
console$ nano index.js
Add the following code to the file.
jsconst express = require('express') const app = express() const port = 3000 app.get('/', (req, res) => { res.send('Hello World from Node.js') }) app.listen(port, () => { console.log(`Application listening on port ${port}`) })
Save and close the file.
This Express application starts an HTTP server on port
3000that returns a plain text response.Allow port
3000through the firewall.console$ sudo ufw allow 3000/tcp
Start the application.
console$ node index.js
The terminal displays
Application listening on port 3000.Open a new terminal session and test the application using
curl.console$ curl http://localhost:3000
A successful response returns:
Hello World from Node.jsPress
Ctrl + Cin the original terminal to stop the application.
Conclusion
You have installed Node.js and npm on an Ubuntu 26.04 server using the NodeSource repository, tested the setup with an Express application, and configured NVM for managing multiple Node.js versions. NVM enables switching between versions without affecting system-wide packages. For more information, refer to the official Node.js documentation.