npm is the package manager for Node.js and the JavaScript coding language. It can be installed on a Linux system and then used on the command line to download and install JavaScript packages and their requisite dependencies.

It's especially useful for developers working with Node.js, as npm's online registry contains a plethora of JavaScript packages that can be browsed and downloaded with ease. It's available for installation on any major Linux distro and operates in much the same way as a distro's package manager, which you're probably already familiar with.

In this guide, we'll show you how to install npm on various Linux distributions. We'll also show you basic usage commands for npm, such as installing and removing software packages.

In this tutorial you will learn:
  • How to install npm on major Linux distributions
  • Basic usage commands for npm
npm on Linux
npm on Linux
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software npm
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ - requires given linux commands to be executed as a regular non-privileged user

Install npm on major Linux distros

Use the appropriate command on your distribution to install npm. On some distributions, npm is installed along with the nodejs package. On others, the two packages are installed separately. The following commands will install both npm and Node.js. Feel free to omit the nodejs package when applicable, but most distributions will install it automatically as a dependency.

To install npm on Ubuntu, Debian, and Linux Mint:

$ sudo apt install npm
OR
$ sudo apt install npm nodejs

To install npm on CentOS 8 (and newer), Fedora, and Red Hat:

$ sudo dnf install npm	# also installs nodejs

To install npm on CentOS 6 and 7, and older versions of Red Hat:

$ sudo yum install epel-release
$ sudo yum install npm # also installs nodejs

To install npm on Arch Linux and Manjaro:

$ sudo pacman -S npm # also installs nodejs

To install npm on OpenSUSE:

$ sudo zypper install npm # also installs nodejs

Once npm is installed, you can begin using it to install or remove JavaScript packages from your system. Check the section below for some common npm commands.


SUBSCRIBE TO NEWSLETTER
Subscribe to Linux Career NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


Basic usage commands for npm

Here's a list of the various npm commands you'll likely need to know:

To see the version of npm and verify it's installed on the system:

$ npm --version

To install a package:

$ npm install package-name

To remove a package:

$ npm uninstall package-name

To search for a particular package:

$ npm search package-name

To see what packages are installed on your system:

$ npm ls

To access the help menu and see a full list of available npm commands:

$ npm help

These are the all commands you'll use when installing and removing packages, as well as searching for them by name. Check the npm help command output for further instructions, as there's a lot more npm can do.

Conclusion

In this guide, we saw how to install npm, the package manager for JavaScript, on all major Linux distributions. We also learned a few of the most common commands to use with npm. As you can tell, npm is tied closely to Node.js and it's recommended that they be installed together. Most distros even list them as dependencies of one another.

FIND LATEST LINUX JOBS on LinuxCareers.com
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.

You may also be interested in:



Comments and Discussions