How to Install npm on Ubuntu: A Step-by-Step Guide

In this guide, we’ll cover what npm is, why you need it, and multiple methods to install npm Ubuntu (including Ubuntu 22.04, 20.04, and older versions).

Updated: 04 Oct, 25 by Susith Nonis 9 Min

List of content you will read in this article:

If you’re working with JavaScript or building Node.js applications on Linux, you’ll realize the importance of npm (Node Package Manager). Ubuntu users often need to install npm Ubuntu, update, and manage packages. Here we’ll cover what npm is, why you need it, and multiple methods to install npm Ubuntu (including Ubuntu 22.04, 20.04, and older versions). 

We’ll also walk through verification, updates, troubleshooting, and essential npm commands to get you started. Whether you’re a beginner exploring Node.js or a system administrator setting up a JavaScript environment, this guide will help you master npm installation on Ubuntu terminal step by step.

Before we dive into the installation, let’s understand npm’s role in modern development.

npm (Node Package Manager) is the world’s largest software registry, containing millions of reusable JavaScript packages. When you’re working on a Node.js project, npm helps you:

  • Install third-party libraries (like Express, React, or Vue).
  • Manage dependencies between packages.
  • Keep your applications up to date with the latest versions.
  • Share your own packages with the developer community.

It’s important to note that npm comes bundled with Node.js. So, when you install Node.js on Ubuntu, npm is automatically included. If you’re new to Linux, you can also read our beginner-friendly guide: What is Ubuntu

Before we start the installation process, make sure you have:

Requirement

Description

Ubuntu System

A working installation of Ubuntu (20.04, 22.04, or other supported versions).

Sudo User Account

A user account with sudo privileges to install and configure software.

Internet Access

Required to download packages, updates, and dependencies.

If you already have Node.js installed, check whether npm is available by running:

npm --version

If this command returns a number, npm is already installed. If not, let’s move forward with the installation steps

The APT (Advanced Package Tool) method is the simplest way to install npm on Ubuntu. It uses the default Ubuntu repositories.

Step 1: Update Package Lists

Always begin by updating your package lists to ensure you get the latest version available in the repository:

sudo apt update

Step 2: Install Node.js

Since npm is bundled with Node.js, install Node.js first:

sudo apt install nodejs

Step 3: Install npm

If npm didn’t come with Node.js, install it separately:

sudo apt install npm

Step 4: Verify Installation

Check the installed versions:

node --version

npm --version

You should now see the installed Node.js and npm version Ubuntu. If both commands return version numbers, you’ve successfully completed your npm installation Ubuntu terminal process using APT.

⚡ Tip: This method may not always provide the latest versions of Node.js and npm. If you need newer releases, consider the NodeSource or nvm methods below.

If you want more control over the Node.js version you install, the NodeSource repository is a better choice. This method ensures you get the latest stable releases.

Step 1: Update Package Lists

sudo apt update

Step 2: Add NodeSource Repository

Download and execute the NodeSource setup script (replace 20.x with your desired version, like 18.x or 16.x):

curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -

Step 3: Install Node.js and npm

sudo apt install -y nodejs

This installs both Node.js and npm in one go.

Step 4: Verify the Installation

node --version

npm --version

With this method, you get the latest stable version of Node.js and npm Ubuntu packages directly from NodeSource, making it ideal for developers who need the newest features.

If you frequently switch between different Node.js projects, you’ll love nvm (Node Version Manager). It allows you to install and manage multiple Node.js and npm versions side by side.

We’ve covered a detailed tutorial here: How to Install NVM on Ubuntu. Below is the quick setup.

Step 1: Install nvm

Run the following command to download and install nvm:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash

Load nvm into your current session:

source ~/.bashrc

Step 2: Install Node.js with nvm

For the latest LTS (Long-Term Support) version:

nvm install --lts

This also installs npm automatically.

Step 3: Switch Between Versions

nvm use 18

(replace 18 with your preferred version).

Step 4: Verify npm Installation

npm --version

Using nvm to install npm Ubuntu gives you flexibility. You can easily upgrade, downgrade, or switch Node.js/npm versions depending on your project’s needs.

After using any of the above methods, confirm npm is installed correctly.

npm --version

This will return your current npm version Ubuntu. To check Node.js:

node --version

If both commands display version numbers, your npm installation Ubuntu terminal setup is complete.

For additional details, you can refer to our separate guide on How to Check NPM Version

Keeping npm updated ensures you benefit from the latest features, bug fixes, and security patches.

To update npm Ubuntu, use:

sudo npm install -g npm@latest

Or, if using nvm:

nvm install-latest-npm

Always verify after updating:

npm --version

This way, you ensure your install node.js and npm Ubuntu setup remains secure and up to date.

Even though installing npm on Ubuntu is usually straightforward, you might run into errors. Here are the most common problems and how to fix them.

1. “npm command not found” error

This happens when npm isn’t installed or isn’t included in your system’s PATH.

Fix:

Verify Node.js installation:

node --version

If npm is missing, reinstall using nvm:

nvm install --lts

Update PATH in .bashrc:

export PATH="$HOME/.npm-global/bin:$PATH"

source ~/.bashrc

2. Missing dependencies while installing packages

Some npm packages require compilation tools.

Fix:
Install build tools and Python:

sudo apt install build-essential python3

Then retry your package installation

3. bcrypt installation errors

The bcrypt package often fails without proper dependencies.

Fix:

sudo apt-get install build-essential python3

npm install bcrypt

If issues persist, clear npm cache:

npm cache clean --force

4. Permission errors with global packages

Using sudo npm install -g can sometimes cause permission problems.

Fix:
Set a custom global directory:

npm config set prefix ~/.npm-global

Add it to PATH:

export PATH="$HOME/.npm-global/bin:$PATH"

Then reload your shell:

source ~/.bashrc

5. Slow or blocked npm installation (proxy issues)

If you’re behind a proxy, configure npm:

npm config set proxy http://<proxy-url>:<port>

npm config set https-proxy http://<proxy-url>:<port>

Once you’ve managed to install npm Ubuntu, here are a few essential commands to kick off your workflow.

Check npm version Ubuntu:

npm --version

Initialize a new project:

npm init -y

Install a local package (saved in package.json):

npm install <package-name>

Install a package globally (accessible everywhere):

npm install -g <package-name>

Update all outdated packages:

npm update

Remove a package:

npm uninstall <package-name>

Check outdated packages with npm-check-updates (ncu):

ncu -u

npm install

These commands form the backbone of everyday Node.js development on Ubuntu.

  • Use nvm for flexible version management instead of relying only on apt.
  • Always keep npm updated (update npm Ubuntu) to benefit from bug fixes.
  • Avoid using sudo npm install -g whenever possible; configure a global prefix.
  • Check your npm version Ubuntu after every update or reinstall.
  • For server deployments, consider running npm on a virtualized environment. You can explore our Linux VPS Hosting to create a stable and isolated setup for your projects.

In this guide, we covered everything you need to know about how to install npm on Ubuntu 20.04:

  • Different methods (APT, NodeSource, nvm).
  • Step-by-step commands for npm installation Ubuntu terminal.
  • How to install Node.js and npm Ubuntu.
  • Verifying installation and update npm Ubuntu.
  • Troubleshooting common errors.
  • Basic npm commands and FAQs.

Now, whether you’re running Ubuntu 22.04, 20.04, or an older version, you have a complete roadmap for setting up npm and starting your Node.js projects confidently.

🚀 Ready to scale your development environment? Boost performance with Linux VPS Hosting from MonoVM and run npm with full control and blazing speed.

npm stands for Node Package Manager. It’s the default package manager for Node.js, allowing developers to install, manage, and update JavaScript libraries.

To install npm on Ubuntu 20.04, simply run: sudo apt update sudo apt install nodejs npm Then verify with: npm --version This ensures a successful npm installation Ubuntu terminal.

No. npm is bundled with Node.js. Installing Node.js automatically provides npm. For maximum flexibility, use nvm to install both.

Run: sudo npm install -g npm@latest or, if using nvm: nvm install-latest-npm This keeps your environment secure and up to date.

This usually means npm isn’t in your PATH. Either reinstall via nvm or manually export the npm binary directory into your PATH (~/.npm-global/bin).

Yes, in most cases. While apt is simple, it often provides outdated versions. nvm lets you install and switch between multiple Node.js/npm versions, which is essential if you manage several projects. For a detailed guide, check our article on How to Install NVM on Ubuntu.

Susith Nonis

Susith Nonis

I'm fascinated by the IT world and how the 1's and 0's work. While I venture into the world of Technology, I try to share what I know in the simplest way with you. Not a fan of coffee, a travel addict, and a self-accredited 'master chef'.

user monovm

Ena Fadel

2024, Aug, 24

This article provides a comprehensive and easy-to-follow guide for installing npm on Ubuntu. The step-by-step instructions make it accessible for both beginners and experienced developers. I appreciate the troubleshooting sections which address common issues like missing dependencies and permission errors. Also, the optional steps for managing npm versions offer great flexibility. Overall, this is an invaluable resource for anyone looking to set up npm on an Ubuntu system!

user monovm

Buford Jakubowski

2024, Oct, 24

Great guide! It's really handy to have a step-by-step walkthrough like this for installing npm on Ubuntu. Your detailed instructions cover all the essentials, and the troubleshooting section is a lifesaver. Many of us can run into snags when dealing with package managers, so knowing how to handle errors and manage multiple versions is super helpful. Definitely bookmarking this for future reference. Thanks for putting this together!

user monovm

Ms. Eva Osinski Jr.

2024, Oct, 24

Great guide on installing npm on Ubuntu! It's thorough and covers all the essential steps. I appreciate the detailed troubleshooting section—it’s super helpful for beginners and those who might run into issues. Including commands for checking versions and managing multiple npm versions is a nice touch. This is an excellent resource for any developer working with JavaScript on Ubuntu. Thanks for sharing such valuable insights!

user monovm

Walter Hyatt I

2025, Jan, 25

This guide is incredibly helpful for anyone looking to install npm on Ubuntu, especially with the detailed, step-by-step instructions provided. Covering different versions of Ubuntu is a great touch, and addressing common issues ensures users can troubleshoot effectively. Additionally, mentioning tools like nvm and npm-check-updates for managing npm versions and packages adds significant value. This makes the process straightforward and accessible for all developers, regardless of their experience level with Ubuntu or npm.

user monovm

Ruben Gusikowski

2025, Feb, 25

This step-by-step guide to installing npm on Ubuntu is fantastic for both newcomers and seasoned developers! Thanks for breaking down the process so meticulously—it makes it so much easier to follow and ensures a smooth setup. I especially appreciate the troubleshooting section; it’s a lifesaver when unexpected issues pop up. If anyone's looking to streamline their JavaScript project setups on Ubuntu, this guide is a must-read. Great job!

user monovm

Luella Stroman MD

2025, Sep, 25

Great post! As someone who frequently works with JavaScript and npm, having a clear and comprehensive guide like this is invaluable. Explaining each step, especially the troubleshooting sections, is really helpful for developers at any level. I especially appreciate the inclusion of details for Ubuntu versions 22.04 and 20.04, as nuances between versions can sometimes trip people up. This makes setting up and managing npm straightforward and efficient on Ubuntu systems. Keep up the awesome work!