How to Install Node JS and NPM Ubuntu 22.04 Linux?

By Hardik Savani May 1, 2024 Category : Ubuntu

Hello Developer,

In this tutorial, you will discover how to install nodejs on ubuntu 22.04. I would like to show you how to install nodejs and npm on ubuntu 22.04. you will learn install node and npm in ubuntu 20.04. This article goes in detailed on ubuntu 22.04 install nodejs 18.

Sure, here's a step-by-step guide to installing Node.js and npm (Node Package Manager) on Ubuntu 22.04 using the command line:

Step 1: Update Package Lists

Before installing Node.js and npm, it's a good practice to update your package lists to ensure you're installing the latest versions of software. Open your terminal and run the following commands:

sudo apt update

Step 2: Install Node.js and npm

Ubuntu 22.04's package repository includes Node.js and npm. You can install them using the `apt` package manager. The default Ubuntu repositories typically provide a slightly older version of Node.js, so if you need the latest version, consider using NodeSource.

To install from the default repositories:

sudo apt install nodejs

sudo apt install npm

This will install Node.js and npm from the Ubuntu repositories. However, it's worth noting that the `npm` package often contains an older version of npm. You can update npm to the latest version using the following command:

sudo npm install -g npm

Step 3: Verify Installation

To verify that Node.js and npm have been installed correctly, you can check their versions with the following commands:

node -v

npm -v

These commands should display the installed versions of Node.js and npm, respectively.

Step 4 (Optional): Install Node.js and npm using NodeSource

If you want to install the latest Node.js and npm versions, you can use the NodeSource repository. Here's how:

First, you'll need to install the required dependencies:

sudo apt install curl software-properties-common

Next, add the NodeSource repository for Node.js:

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

This command adds the Node.js 16.x repository. You can change the version number if you need a different version.

Now, install Node.js and npm:

sudo apt install nodejs

This will also install npm. Verify the installation as mentioned in "Step 3."

That's it! You've successfully installed Node.js and npm on your Ubuntu 22.04 system. You can now start using Node.js for your development projects.

I hope it can help you...

Tags :
Shares