How to install and update Nodejs on Ubuntu 20.04 LTS
- Using Command
- Install Specific Nodejs version.
- Download
tar.xz
the file then install it. - Update Nodejs:
- Uninstall NodeJs.
- Uninstall the previous version then install the specific version:
1st way:
Step 1: Open your terminal or press Ctrl + Alt + T
Step 2: To install node.js use the following command:
sudo apt-get install nodejsnode -v //Check Nodejs Version:or node –version
Step 4: In most cases, you’ll also want to also install npm
,(Node.js package manager.). Install by the following command:
sudo apt install npm
2nd Way
Install Specific Nodejs version.
Install Specific Node.js version using the NodeSouce repository: the latest version of Node.js can be installed from the NodeSource repository. Follow the steps below to install the Node.js on your Ubuntu.
Step 1: Open your terminal or press Ctrl + Alt + T.
Step 2: Install curl:
sudo apt-get install curl
Step 3: Add Node.js PPA to the system.
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt-get install -y nodejs
Note: Here, we are installing node.js version 16, if you want to install version 14, you can replace setup_16.x with setup_14.x. or the following link.
Step 4: Install Node.js:
sudo apt-get install -y nodejs
Step 5: Check version:
node -v or node –versionnpm -v or npm –version
Congratulation, you have successfully installed Node.js and NPM on your Ubuntu machine.
3rd way
Step 01: Download Node.js
sudo apt update //update system repositoriessudo apt install xz-utils // install the package xz-utils.sudo tar -xvf node-v16.17.0-linux-x64.tar.xz //extract .tar.xz file.sudo cp -r node-v16.17.0-linux-x64/{bin,include,lib,share} /usr/export PATH=/usr/node-v16.17.0-linux-x64/bin:$PATH //update Pathnode --version
Update Nodejs.
- Update npm
npm install npm@latest -gnpm cache clean -f //clean npm cache
npm install -g n //install n Node’s version manager:n latest //update node to the latest versionsudo n [version.number] //Install a specific version:orsudo n 16.04
Uninstall NodeJs:
sudo npm uninstall -g norsudo apt-get remove nodejsorsudo apt purge nodejs
Uninstall the previous version then install the specific version:
sudo apt-get purge --auto-remove nodejs
curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs