How to install Node.js and npm on Ubuntu 20.04

Node.js is a runtime environment that has all the prerequisites for properly executing JavaScript files on your system. It is based on Chrome’s V8 JavaScript engine and uses the non-blocking I / O model. Npm is a package from Node.js and is a collection of almost all of the open source libraries on the Internet.

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:

$ sudo apt update

$ sudo suitable To install nodejs

Verify the installation by checking the version of Node.js you downloaded:

$ nodejs -v

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:

$ sudo suitable To install Above the sea level

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:

$ Beckon -Ö- | bash

Paste it into the command terminal and run it to install the nvm. Then run the following command to get your bash file.

$ source ~/.bashrc

Enter the following command to see which versions of Node are available for download:

$ nvm list-remote

Then add the version you want to download in the following command syntax:

$ nvm To install v(Version number)

For example, to download v14.9.0, write the command like this:

$ nvm To install v14.9.0

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:

$ nvm To install lts/Erbium

You can view all versions of Node installed on your system by typing:

$ nvm list

Use the following command to enter a different version of Node:

$ nvm use v14.9.0

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.

Related Posts