How to Install Node.js and Npm on Ubuntu 22.04

Node.js is an open-source and cross-platform runtime environment of JavaScript. It is developed to run the JavaScript code without the web browser. It is the prior choice of developers for front-end and back-end development.

Npm is a large software registry developed and maintained by NPM Inc. It is known as a package manager for Node.js. NPM comprises two major parts: a command-line interface and the repository that contains the JavaScript packages.

In this descriptive blog, we will demonstrate possible methods to install Node.js and Npm on Ubuntu 22.04. The outcomes of this write-up will:

So, let’s have a look at the first method:

Method 1: Install Node.js and Npm Using the Default Repository of Ubuntu 22.04

Ubuntu comes with the packages of Node.js and Npm in its default packages repository. The following steps are carried out to install Node.js and Npm on Ubuntu 22.04:

Step 1: Update system packages

To adopt the updated/latest packages, update the core packages repository. For this purpose, run the following command:

$ sudo apt update

The core repository of the system is updated.

Step 2: Install Node.js & Npm

To install Node.js & Npm, run the following command:

$ sudo apt install nodejs npm

Node.js & Npm are installed successfully on Ubuntu 22.04.

Step 3: Verify the installation

To verify the successful installation of Node.js, check the version of installed Node.js using the following command:

$ node --version

The output showed that the installed Node.js version is v12.22.9.

To verify the Npm version, utilise the below-mentioned command:

$ npm --version

The installed Npm version is v8.5.1.

Method 2: Install Node.js and Npm Using NodeSource

NodeSource is a navigator that enhances Node.js power. It is used to install Node.js & Npm on Ubuntu 22.04. Therefore, for this purpose, follow the step-by-step process given below:

Step 1: Install Curl

Here, Curl is a prerequisite that will be used to download the NodeSource script. To install Curl, use the following command:

$ sudo apt install curl

Curl is installed successfully.

Step 2: Download NodeSource Script

Here, we are downloading the latest version (setup_18.x). However, you can use any version (latest or stable) by putting the version in the command at the place of setup_18.x. For example, 16.x or 17.x based on your requirements.

To download the Nodesource Script, use the following command in the Ubuntu terminal:

$ curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -

NodeSource script is downloaded.

Step 3: Update the system’s repository

When the prerequisites are installed, you must update the system’s core repository to get the latest packages. To fulfill this purpose, execute the command as follows:

$ sudo apt update

The installed packages are up to date.

Step 4: Install Node.js and Npm

This package includes Node.js and Npm. To install Node.js & Npm, execute the below command:

$ sudo apt install nodejs

Node.js & Npm have been installed successfully.

Step 5: Verify the installation

To verify the successful installation, check the version of installed Node.js using the following command:

$ node --version

The output showed that the installed Node.js version is v18.4.0.

For the Npm version, execute the command:

$ npm --version

The installed Npm version is 8.12.1.

How to Remove Node.js and Npm From Ubuntu 22.04?

If you install Node.js and Npm on Ubuntu 22.04 using a terminal, you can remove both of them using the following command:

$ sudo apt purge nodejs

Node.js and npm both are removed successfully from Ubuntu 22.04.

That’s it! You have experienced all possible methods of Node.js and Npm to install on Ubuntu 22.04.

Conclusion

Node.js and Npm can be installed on Ubuntu 22.04 using the Ubuntu official repository or NodeSource. Node.js is an open-source and cross-platform runtime environment of JavaScript. It is developed to run the Javascript code without the web browser. Npm is known as the default package manager for Node.js.