How to Install Node.js and NPM on Ubuntu

Node.js is a powerful runtime environment that allows developers to run JavaScript outside the browser. It is widely used for backend development and high-performance web applications. Together with npm (Node Package Manager), it forms a complete environment for handling JavaScript projects efficiently.

In this guide, you will learn how to Install Node.js and npm on Ubuntu using different methods including Ubuntu’s default repository and NVM (Node Version Manager). Whether you want to install nodejs ubuntu or setup nvm ubuntu, this step-by-step guide will help you do it easily.

What is NPM and Why It’s Used

The NPM is the official package manager for Node.js. It helps developers share and reuse code efficiently by installing libraries from its online registry. You can install frameworks like Express, React, or Vue with a single command using npm.

For example, when you start a new Node.js project, npm allows you to install dependencies, manage versioning, and automate tasks through scripts. This makes development faster and more organized. Without npm, manually managing each dependency would be time-consuming and prone to errors.

Installing Node.js and npm Using Ubuntu’s Default Repository

Ubuntu’s default repository provides a simple way to get Node.js and npm running quickly. While it might not always contain the latest version, it’s perfect for lightweight projects or testing.

Before moving forward, we need to update system package. Open your terminal and enter below command:

sudo apt update

Once your repositories are updated, you can install Node.js directly from Ubuntu’s default software source. This adds the Node.js runtime to your system so you can run JavaScript applications.

sudo apt install nodejs -y

npm, also known as Node Package Manager, doesn’t always come bundled with the Node.js package in Ubuntu. Install it separately to manage libraries and project dependencies easily.

sudo apt install npm -y

Install Node.js and npm on Ubuntu Using NVM

If you want more control over Node.js versions, you can use NVM. It lets you install and switch between different Node.js versions easily. This method is ideal when you work on multiple projects that require different setups.

1. Install curl (if not already installed):

sudo apt install curl -y

2. Download and install NVM:

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

3. Activate NVM:

source ~/.bashrc

4. Verify installation of node version manager using below command:

nvm --version

5. Install Node.js and npm using NVM:

nvm install node

With NVM, you can install multiple Node.js versions and switch between them easily using. Here you have already installed latest version of Node.js by entering these command.

Checking if Node.js and NPM Are Installed

Once you complete the installation, you should confirm that both Node.js and npm are working correctly.

Run the following commands to verify installation of Node.js and NPM:

node -v
npm -v

Output:

v22.9.0
10.8.2

If you see version numbers displayed similer to above output, it means you have successfully completed the install nodejs ubuntu process. You can now start building projects using Node.js and npm.

Conclusion

Now you know how to install Node.js and npm on Ubuntu using both the Ubuntu repository and NVM. Installing using the repository is quick and stable, while using NVM provides better control over versions. Node.js allows you to build fast and scalable applications, and npm gives you access to thousands of ready-to-use open source tools.

After installing Node.js and npm, the next step is to explore the tools that make development faster and easier. Check out our detailed guide on Top 20 Node.js Packages Every Developer Should Master to discover the most useful packages that can enhance your workflow and boost productivity.