Install npm on Ubuntu
How To

Install NPM on Ubuntu

Sagar Sharma
Sagar Sharma

Table of Contents

NPM is nothing but a package manager for the Noje.js projects that lets you install and manage them on your system.

You can think of NPM as similar to apt but mean specific to the noje.js projects.

And in this tutorial, I will show you how you can install the NPM package manager in Ubuntu and walk you through the primary use of NPM.

How to install and use NPM in Ubuntu

The NPM is available in the default repository of Ubuntu and can easily be installed with the following command:

sudo apt install nodejs npm

The reason why I installed nodejs package as it is pretty small and if you are a developer, you are going to install it anyway.

Once you are done with the installation, you can use the given command to check the installed version of npm:

npm -v
how to check installed version of npm in ubuntu

If you want the latest version of NPM, you can add the official node repository and install it from there. The article below shows the steps.

How to Install Node.js on Ubuntu
Learn various ways of installing Node.js on Ubuntu, be it the recent version or the LTS version.

How to install packages using NPM in Ubuntu

To install any desired package, knowing the exact keyword is necessary, and similar to apt search where you search packages, you can do the same with the npm.

To search for a specific package, all you need to do is append the name of the package with the search option:

npm search package_name

For example, here I am looking for Express (lightweight framework):

npm search express web framework
search npm packages in ubuntu

The reason why added web and framework is that npm will also look for keywords specific to that package so that you can find the one for you quite easily.

Once you find the exact keyword of the package, you can use the following command syntax for installation:

npm install package_name

Here, I want to install a package named express so I will  be using the following command:

npm install express

Once done, you can list the installed packages using the following:

npm list
list installed npm packages in ubuntu

How to remove NPM packages from Ubuntu

If you no longer need a package, it can easily be removed by using the following command syntax:

npm uninstall package_name

Let's say I want to remove a package named express so I will be using the following command:

npm uninstall express

Now, you can list the installed packages so that you can be assured of whether the package has successfully been removed or not:

list npm packages in ubuntu

And as you can see, the express package is no longer listed!

Wrapping Up

This was a quick tutorial on installing the NPM package manager in Ubuntu with some basic use cases.

And if you have any doubts about this topic, feel free to let me know in the comments.