---
title: How to Install Node.js and NPM on Ubuntu 22.04
url: https://docs.vultr.com/how-to-install-nodejs-and-npm-on-ubuntu-2204
description: Learn how to install Node.js and NPM on Ubuntu 22.04 with this step-by-step guide. Includes multiple installation methods and troubleshooting tips.
publish_date: 2025-04-29T12:01:30.271000Z
last_updated: 2025-04-29T12:08:58.650000Z
author: Aashish Chaurasiya
header_image: https://docs.vultr.com/public/doc-assets/2173/787ea52a-9643-4412-a20c-0eef957fe330.png
---

> Index of every Vultr Docs page in markdown: https://docs.vultr.com/llms.txt

Node.js is an open-source, cross-platform JavaScript runtime for building scalable server-side applications. NPM manages libraries, dependencies, and scripts in Node.js projects, enabling server-side JavaScript use.

This article demonstrates how to install Node.js and NPM on Ubuntu 22.04. You will install both using the NodeSource PPA and manage multiple Node.js versions with NVM (Node Version Manager) on your server.

## Prerequisites

Before you begin:

* Have an [Ubuntu 22.04 server](https://www.vultr.com/servers/ubuntu/).

* Access the server using SSH as a non-root user with sudo privileges.

* [Update the Ubuntu server](https://docs.vultr.com/how-to-update-a-vultr-cloud-server#how-to-update-debian-&-ubuntu).

## Choose a Node.js Version

When selecting a Node.js version, consider the following:

* **Latest Release**: Contains the newest features and updates. Ideal for projects needing the latest functionality.
* **LTS Release**: Stable, long-term supported version. Best for production environments.

Factors to consider:

* **Stability**: Use the latest LTS for production.
* **Features**: Use the latest release for new features.

## Install Node.js

The Ubuntu 22.04 APT repositories may not have the latest Node.js version. To install the latest version, use the NodeSource PPA for the most up-to-date repository information for a specific Node.js version.

1. Update the server package index.

    ```console
    $ sudo apt update
    ```

1. Download your desired Node.js version PPA installation script. For example, run the following command to use the Node.js version `22.x`.

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

    Visit the official NodeSource documentation to verify [all available Node.js versions](https://github.com/nodesource/distributions?tab=readme-ov-file#debian-and-ubuntu-based-distributions) you can install on your server.

1. Run the Node.js setup script.

    ```console
    $ sudo -E bash nodesource_setup.sh
    ```

1. Install Node.js and NPM using the following command.

    ```console
    $ sudo apt-get install -y nodejs npm
    ```

1. View the installed Node.js version on your server.

    ```console
    $ node -v
    ```

    Output:

    ```
    v22.14.0
    ```

1. View the installed NPM version on your server.

    ```console
    $ npm -v
    ```

    Output:

    ```
    10.9.2
    ```

## Test the Installation

1. Create a new project directory such as `example-site`.

    ```console
    $ mkdir example-site
    ```

1. Switch to the directory.

    ```console
    $ cd example-site
    ```

1. Initialize a new Node.js project using `npm`.

    ```console
    $ npm init -y
    ```

1. Install the `express` module using `npm`.

    ```console
    $ npm install express
    ```

1. Create a new `index.js` application file.

    ```console
    $ nano index.js
    ```

1. Add the following code to the file.

    ```js
    const express = require('express')
    const app = express()
    const port = 3000

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

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

    Save and close the file.

    The above Node.js code creates an Express application that listens on port `3000` and outputs a `Hello World! Greetings from Vultr` message.

1. Allow port `3000` through the firewall to enable network connections to the application.

    ```console
    $ sudo ufw allow 3000
    ```

1. Reload the firewall to apply changes.

    ```console
    $ sudo ufw reload
    ```

1. Start the Node.js application.

    ```console
    $ node index.js
    ```

1. Access your Node.js application using your server IP and port `3000` in a web browser such as Chrome.

    ```
    http://<server-ip>:3000
    ```

## Install Multiple Versions with Node Version Manager (NVM)

NVM (Node Version Manager) allows you to install and switch between multiple Node.js versions on your server. Follow the steps below to install various Node.js versions using NVM based on your project needs.

1. Download the latest NVM installation script on your server.

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

    Please, refer to the NVM documentation to get the [latest version](https://github.com/nvm-sh/nvm?tab=readme-ov-file#installing-and-updating) at the time of your installation.

1. Run the script to install NVM in your user environment.

    ```console
    $ bash install.sh
    ```

1. Reload your server environment variables.

    ```console
    $ source ~/.profile
    ```

1. List all available Node.js versions you can install on your server.

    ```console
    $ nvm ls-remote
    ```

    Your output should look like the one below.

    ```
    ...
    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
    ```

1. Install a specific Node.js version. For example, Node.js 20.

    ```console
    $ nvm install 20
    ```

1. List all installed Node.js versions and verify the default version on your server.

    ```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)
    ```

1. Run the following command to install a specific Node.js version such as `20` using NVM.

    ```console
    $ nvm use 20
    ```

    Output:

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

1. View the active Node.js version in your user environment.

    ```console
    $ node -v
    ```

    Output:

    ```
    v20.14.0
    ```

1. View the NPM version in your user environment.

    ```console
    $ npm -v
    ```

    Output:

    ```
    10.7.0
    ```

1. Run the following command to a specific version as the default Node.js version in your environment.

    ```console
    $ nvm alias default 20
    ```

## Conclusion

In this article, you installed Node.js and NPM on your Ubuntu 22.04 server. You can now develop server-side applications and manage multiple Node.js versions using Node Version Manager (NVM).
