Categories: ErrorhatUbuntu

How To Install Node.js on Ubuntu 20.04

Introduction

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:

  • using apt to install the nodejs package from Ubuntu’s default software repository
  • using apt with an alternate PPA software repository to install specific versions of the nodejs package
  • installing nvm, the Node Version Manager, and using it to install and manage multiple versions of Node.js
Sponsored

For 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.

Prerequisites for installing NodeJS on Ubuntu

This tutorial will assume the following: errorhat

  • Ubuntu 20.04 server (although desktop should still work)
  • Non-root user
  • General understanding of Command-Line tools

Let’s Get Started

Install Node.js and npm from the Ubuntu repository

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

Installing using Node Version Manager

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:

  • v14.x – The latest stable version.
  • v13.x
  • v12.x – The latest LTS version.
  • v10.x – The previous LTS version.

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:

Sponsored
 $ 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 

Conclusion

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.

Go to Source

Ubuntu Server Admin

Recent Posts

Ubuntu Command-Line Mastery: The Essential Guide for Power Users

The Linux terminal is a powerful tool allowing users to control their system precisely and…

8 hours ago

Ubuntu Weekly Newsletter Issue 876

Welcome to the Ubuntu Weekly Newsletter, Issue 876 for the week of January 19 –…

3 days ago

How to utilize CPU offloads to increase storage efficiency

Canonical Ceph with IntelⓇ Quick Assist Technology (QAT) Photo by v2osk on Unsplash When storing…

4 days ago

Breaking the Rules: RPC Pattern with Apache Kafka and Karafka

Introduction Using Kafka for Remote Procedure Calls (RPC) might raise eyebrows among seasoned developers. At…

4 days ago

How to Install PalWorld on Ubuntu VPS (Easy 5 Minute Guide)

This article provides a guide for how to install PalWorld on Ubuntu VPS server. How…

5 days ago

How to Resolve Unmet Dependencies Error on Ubuntu

Using APT to manage software on Ubuntu (or similar Linux systems) is generally simple. It…

6 days ago