Via Using NodeSource Repository
We can also directly install node.js and npm using the official node source repository, for this, we follow the steps mentioned:
Step 1: Install Curl
First, we will have to install curl so that we can download third-party repositories easily, for this we will run the following command:
sudo apt update
sudo apt install -y curl
This will install the curl into to Ubuntu system, it will show “already installed” if your system has curl already otherwise it will install it for you.
Step 2: Curl the Directory
Now we will have to curl the source directory to install the node.js and npm, for this we run the following command:
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - &&\
sudo apt-get install -y nodejs
Note: Here we are using setup_18.x because it’s the latest version available for ubuntu, you can check if newer version is available and change the command accordingly.
This will install the node.js and npm on your system successfully.
How to Install Node.js and npm on Ubuntu?
As you may be aware already, npm and node.js are very powerful web development tools that are used for full-stack development purposes. It is straightforward if you ever want to install npm or node.js in the Windows operating system. In this article, we will cover some effective methods that you can use to install npm as well as node.js in your required distribution.