How to install node. Js on ubuntu 20. 04

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.

See also  Darktable 4.6.0 Released! Auto-Save, rgb primaries Module [Ubuntu PPA]

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:

Sponsored

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 

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


Discover more from Ubuntu-Server.com

Subscribe to get the latest posts sent to your email.

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply