Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast, scalable network applications. This tutorial will provide you with 2 methods to install Node.js on your Ubuntu 20.04 LTS Linux system. Use official PPA to install Node.js on your systems, or use nvm (node version manager) to install Node.js.
Node Version Manager is a helpful utility to install and manage multiple node.js versions on any system. NVM install node.js under the current user home directory. So any node.js version installed with nvm is accessible for that user only. To use node.js for multiple users, you need to log in to that user and install the required node.js version there.
Prerequisites
You must have shell access to your Ubuntu 20.04 system with sudo privileged account. Login to your system and open a terminal.
Choose one of the below options to install Node.js on the Ubuntu 20.04 LTS system. Option 1 is used to install Nodejs with NVM on Ubuntu and option 2 will show your instruction to install Node.js on Ubuntu 20.04 via PPA.
Method 1 – Install Node.js via NVM on Ubuntu 20.04
NVM provides a shell script for the installation on the Linux system. So, execute the installer script with the below commands. This will install the nvm command on your system.
sudo apt install curl
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
Now, load the nvm environment in the current shell with the below command.
source ~/.profile
NVM is successfully installed on your system. Now you can install any node.js version with the help of NVM.
nvm install 16.14
You can run the above command with different-2 versions to install any number of Node.js on the Ubuntu system. For example you can use nvm install 17
or nvm install 12.18
etc.
The systems have multiple node.js versions installed, can use the below command to set any installed node.js version as an active version.
nvm use 16.14
You can find the detailed instruction’s about the node.js installation in our previous tutorials. Find more details about Node.js installation via NVM.
Method 2 – Install Node.js with Official Node PPA
The official team provides a repository for the Node.js installation on the Ubuntu system. But it has limitations to installing a single version at a time. You can use multiple versions on a single system similar to nvm.
Run the below commands to enable PPA to your system.
sudo apt install curl
curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
Once you add the repository, install Node.js by executing the following command.
sudo apt install nodejs
Once you complete the installation, run the below command to view the current Node.js version.
node -v
Output
v16.14.0
Conclusion
You have learned to install Node.js on Ubuntu 20.04. In this tutorial, you found two methods for installing node.js on Ubuntu. Next you may need to install Yarn package manager for Node.js, which have multiple benefits over npm.