This article will show you how to get Node.js working on your Ubuntu 20.04 system with a non-root user account with sudo permissions.
There are two installation methods that we’re going to look at:
- Install Node.js from the official Ubuntu repository
- Install Node.js with nvm
Method 1: installing Node.js from the official Ubuntu repository
Installing Node.js using a suitable package manager from the official Ubuntu repository is pretty straightforward. First, before running the install command, update your package list by typing:
Verify the installation by checking the version of Node.js you downloaded:
The process shown above should download the latest package available in Ubuntu’s software repository. To download a specific version, try one of the other methods in this tutorial.
You can install npm the same way we installed Node.js with the apt repository. Enter the following command to start the npm installation:
You have now installed npm and Node.js on your system. You can now start using node.js and the npm library to add functionality to the software on your system.
Method 2: using NVM to install Node.js
If you want to download a specific version of Node or just want more customizability with the installation, nvm can do it for you. Nvm stands for Node Version Manager and is a tool with which you can manage multiple active nodes side by side. js versions on your system.
First, copy the curl command from the readme file on the GitHub page for nvm:
Paste it into the command terminal and run it to install the nvm. Then run the following command to get your bash file.
Enter the following command to see which versions of Node are available for download:
Then add the version you want to download in the following command syntax:
For example, to download v14.9.0, write the command like this:
You have now successfully downloaded Node.js v14.9.0 and installed it on your system. You can use nvm to download multiple different versions without the versions interrupting each other. You can even download and install long-term support versions of Node with nvm, e.g. B. Erbium or Dubnium. For example, the following command installs the latest version of Erbium:
You can view all versions of Node installed on your system by typing:
Use the following command to enter a different version of Node:
Nvm is a great tool as it combines many options for efficiently managing the Node.js software.
Wrap up
This tutorial explored two different ways to install Node.js on an Ubuntu 20.04 server: using nvm and by requesting the program directly from the standard Ubuntu repository. If you want to get the latest version installed as soon as possible, you should choose the first method. If you want more flexibility in your installation, you can choose one of the two methods.
Check out the ones from Nodeproject official homepage to learn more about using Node on your Ubuntu 20.04 system.