How to Install NPM on Ubuntu 24.04

Node Package Manager or NPM is the default package manager for Node.js that helps you manage dependencies (modules and libraries) required to run Node.js applications. NPM is a repository of hundreds of thousands of useful code pieces that can integrate with your Node.js project and allow you to develop scalable applications. With the help of NPM, you can install, update, remove, and manage the dependencies needed for your projects. 

Now, that Ubuntu 24.04 has been released, it has become your main responsibility to install applications that most projects frequently need. NPM is one among them that streamlines your development process and allows you to have control over Node.js applications on Ubuntu. 

You can read this tutorial to find:

How to Install NPM on Ubuntu 24.04

You can install NPM on Ubuntu 24.04 through:

How to Install NPM on Ubuntu 24.04 Through Ubuntu Standard Repository

The Ubuntu 24.04 standard repository includes an NPM package that you can install from the apt command, however, it doesn’t install the NPM’s latest version on the system. 

Before you begin the NPM installation on Ubuntu through this method, first update the repository using the below-provided command:

sudo apt update && sudo apt upgrade -y
Install NPM on Ubuntu 24.04 a

Once the repository is updated, execute the below-given command to install NPM on Ubuntu:

sudo apt install npm -y
Install NPM on Ubuntu 24.04 b

To confirm the NPM installation on Ubuntu, use the below-provided command:

npm --version
Install NPM on Ubuntu 24.04 c

Note: In case you want to remove NPM from Ubuntu 24.04, use the below-given command:

sudo apt remove npm -y
Install NPM on Ubuntu 24.04 d

How to Install NPM on Ubuntu 24.04 Through Node Source Repository

Adding the node source repository to install the Node.js on Ubuntu is the official method provided by the developers. The advantage of using the node source repository method is that users will be able to install Node.js and NPM’s latest version on Ubuntu. 

To install NPM on Ubuntu 24.04 through the node source repository, use the following steps:

Step 1: Install curl on Ubuntu

First, install the curl command line utility on Ubuntu as a dependency needed for this method, it can be done using the below-provided command:

sudo apt install curl -y
Install NPM on Ubuntu 24.04 e

Step 2: Add Node Source Repository 

Next, run the below-mentioned curl command to add the node source repository to Ubuntu for installing the node’s latest version on the system.

curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
Install NPM on Ubuntu 24.04 f

Note: The Node.js latest version was 22.1.0 at the time of writing our tutorial. For an older version, you can replace 22.x with any desired number. For example, for installing Node.js 18, you can use 18.x and so on.

Step 3: Install Node.js on Ubuntu

After you added the node source repository, you can install Node.js on Ubuntu from the following command:

sudo apt install nodejs -y
Install NPM on Ubuntu 24.04 g

The above command will also install NPM’s latest version along with Node.js on Ubuntu. 

Step 4: Confirm NPM Installation 

Once you complete the Node.js installation, you can confirm the NPM installation on Ubuntu through the following command:

npm --version
Install NPM on Ubuntu 24.04 h

Note: Removing NPM from Ubuntu 24.04 installed through this method is simple. It can be completed by removing the Node.js from the system using the following command:

sudo apt remove nodejs -y
Install NPM on Ubuntu 24.04 i

You can also remove the node source repository from Ubuntu using the below-given command:

sudo rm /etc/apt/sources.list.d/nodesource.list
Install NPM on Ubuntu 24.04 j

How to Install NPM on Ubuntu 24.04 Through Node Version Manager

Node Version Manager or NVM is another useful method that can be used to install NPM on Ubuntu 24.04. This method will help you install multiple Node.js and NPM versions on your system, allowing you to switch to any version within seconds. 

To install NPM on Ubuntu 24.04 from NVM, use the following steps:

Step 1: Download and Run NVM Installer Script

First, navigate to the NVM GitHub release page and find out the latest version script command. At the time of installation, the NVM’s latest version was 0.39.7, and the command to download and execute the script is given below:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
Install NPM on Ubuntu 24.04 k

When the script completes the installation of NVM on Ubuntu, you will be provided with the desired export output highlighted in the picture:

Install NPM on Ubuntu 24.04 l

You can copy the desired export command and run it on your terminal, or reopen the terminal to apply the changes.

Step 2: Confirm NVM Installation

To ensure NVM is installed on Ubuntu, use the following command:

nvm --version
Install NPM on Ubuntu 24.04 m

Step 3: Check Node’s Version Through NVM

To check for different Node.js versions that you can install through NVM, use the below-given command:

nvm ls-remote
Install NPM on Ubuntu 24.04 n

Step 4: Check Node’s Version Through NVM

To install the Node.js desired version on Ubuntu through NVM, you can use the following syntax:

nvm install node_version

Here, we are installing Node.js version 22.1.0 on Ubuntu using the following command:

nvm install 22.1.0
Install NPM on Ubuntu 24.04 o

The above command will install Node.js with the desired NPM version on your system.

Step 5: Confirm NPM Installation Through NVM

To confirm whether NVM successfully installs NPM on Ubuntu, you can again use the following version command:

npm --version
Install NPM on Ubuntu 24.04 p

Note: To remove NPM from Ubuntu 24.04 installed through NVM, first deactivate the NVM using the following command:

nvm deactivate
Install NPM on Ubuntu 24.04 q

Then uninstall the desired Node.js version to remove the NPM package associated with it. Since we have installed the Node.js 22.1.0 version, we can remove it from Ubuntu using the following command:

nvm uninstall 22.1.0
Install NPM on Ubuntu 24.04 r

This will also remove NPM version 10.7.0 associated with the Node.js package on Ubuntu.

Conclusion

NPM is a package manager for managing Node.js projects that can be installed on Ubuntu 24.04 from the Ubuntu standard repository using the “apt install npm” command. However, the Ubuntu standard repository doesn’t ensure installing the NPM latest version on your system. You can add a node source repository to Ubuntu and install the Node.js from the “apt install nodejs” command to install NPM latest version. Besides that, you can also install NVM on Ubuntu from the script and install your desired Node.js version along with NPM on your system. 

All the methods discussed in this guide are easy to follow and ensure installing the NPM on the Ubuntu 24.04 system. You can choose your desired method and start creating servers, applications, scripts, and command line tools with Node.js and NPM.