Installing Node.js on Ubuntu 20.04 can be done using a few different methods. Here’s one of the most common ways using the official NodeSource repository:
Method 1: Using NodeSource Repository-
Update package lists:
sudo apt update
-
Install necessary packages:
sudo apt install curl -y
-
Install Node.js from the NodeSource repository:
-
Add the NodeSource repository:
curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
(You can replace
14.x
with the version you want to install, like16.x
for Node.js 16) -
Install Node.js and npm:
sudo apt install nodejs -y
-
Add the NodeSource repository:
-
Verify the installation:
Check the Node.js version:
node -v
Check the npm version:
npm -v
-
Update package lists:
sudo apt update
-
Install Node.js from the default Ubuntu repository:
sudo apt install nodejs npm -y
-
Verify the installation:
Check the Node.js version:
node -v
Check the npm version:
npm -v
Choose the method that suits your preferences. Method 1 allows you to install a specific Node.js version by choosing the appropriate NodeSource repository, while Method 2 installs the versions available in the default Ubuntu repository.
Let me know if you encounter any issues or need further assistance!