Open Terminal
Update package lists: `sudo apt update`
Install prerequisites: `sudo apt install -y curl ca-certificates`
Add NodeSource repository for the desired Node.js version: `curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -`
Install Node.js: `sudo apt install -y nodejs`
Verify installation: `node -v`
Verify npm installation: `npm -v`
Optional: install build tools: `sudo apt install -y build-essential`
Optional: install a specific Node.js version with NVM:
Install NVM: `curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash`
Load NVM: `source ~/.bashrc`
Install Node.js LTS with NVM: `nvm install –lts`
Set default Node.js version with NVM: `nvm alias default lts/*`
Verify NVM-managed Node.js: `node -v`
Verify NPM with NVM: `npm -v`
