Step 1: Update the System
First, make sure your system is up-to-date:
sudo apt update
sudo apt upgrade -y
Step 2: Add the NodeSource Repository for Node.js 20
Use the NodeSource setup script to add the repository for Node.js 20:
(before running following command check it the /etc/apt/sources.list.d does exits)
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
Step 3: Install Node.js
Once the repository is added, install Node.js and npm:
sudo apt install -y nodejs