How To Install Node.js on Ubuntu 20.04
Node.js is a JavaScript runtime for server-side programming. It allows developers to create scalable backend functionality using JavaScript, a language many are already familiar with from browser-based web development.
In this guide, we will show you three different ways of getting Node.js installed on an Ubuntu 20.04 server:
apt
to install the nodejs
package from Ubuntu’s default software repositoryapt
with an alternate PPA software repository to install specific versions of the nodejs
packagenvm
, the Node Version Manager, and using it to install and manage multiple versions of Node.jsFor many users, using apt
with the default repo will be sufficient. If you need specific newer (or legacy) versions of Node, you should use the PPA repository. If you are actively developing Node applications and need to switch between node
versions frequently, choose the nvm
method.
This tutorial will assume the following: errorhat
At the time of writing, the Node.js version included in the Ubuntu 20.04 repositories is 10.19.0
which is the previous TLS version.
The installation is pretty straightforward. Run the following commands to update the package index and install Node.js and npm:
$ sudo apt update -y ; sudo apt upgrade -y $ sudo apt install nodejs npm
The command above will install a number of packages, including the tools necessary to compile and install native addons from npm.
Once done, verify the installation by running:
$ nodejs --version
output v10.19.0
NodeSource is a company focused on providing enterprise-grade Node support. It maintains an APT repository containing multiple Node.js versions. Use this repository if your application requires a specific version of Node.js.
At the time of writing, NodeSource repository provides the following versions:
We’ll install Node.js version 14.x:
1. Run the following command as a user with sudo privileges to download and execute the NodeSource installation script:
$ curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
The script will add the NodeSource signing key to your system, create an apt repository file, install all necessary packages, and refresh the apt cache.
If you need another Node.js version, for example 12.x
, change the setup_14.x
with setup_12.x
.
2. Once the NodeSource repository is enabled, install Node.js and npm:
$ sudo apt install nodejs
The nodejs package contains both the node
and npm
binaries.
3. Verify that the Node.js and npm were successfully installed by printing their versions:
$ nodejs --version
output v10.19.0
$ npm --version
output 6.14.4
To be able to compile native addons from npm you’ll need to install the development tools:
$ sudo apt install build-essential
There are a quite a few ways to get up and running with Node.js on your Ubuntu 20.04 server. Your circumstances will dictate which of the above methods is best for your needs. While using the packaged version in Ubuntu’s repository is the easiest method, using nvm or a NodeSource PPA offers additional flexibility.
We hope the “How to Install Node.js” and “npm” on “Ubuntu 20.04” help you. If you have any query regarding “How to Install Node.js” and “npm” on “Ubuntu 20.04” drop a comment below and we will get back to you at the earliest.
The post How To Install Node.js on Ubuntu 20.04 appeared first on Error Hat.
You’ve recently installed VMware Workstation on your Ubuntu system and encountered the frustrating “Could not…
Have you ever found yourself staring at a terminal full of 404 errors while trying…
One particularly frustrating error that many users face when trying to upgrade from Ubuntu 18.04 …
In the world of containerization, time synchronization issues can create unexpected roadblocks when working with…
If you’ve recently upgraded to Ubuntu 23.04 or newer, you might have encountered a frustrating…
Canonical announces the General Availability of Ubuntu for the NVIDIA® Jetson Orin™ for edge AI…