A step-by-step guide to installing Node.js on ubuntu

A step-by-step guide to installing Node.js on ubuntu

Introduction

Node.js is a JavaScript runtime for serverside programming. It's built on Google Chrome's V8 JavaScript engine. It allows developers to create fast, highly scalable, and data-intensive applications.

In this guide, I will show how one can install node.js on ubuntu 20.04 and beyond. We will install it using apt with PPA software repository to install specific versions of the nodejs

Installing Node.js with using apt and the NodeSource PPA

To upgrade or install a different kind of version of node.js, one can use a personal package archive (PPA) that is extensively managed and maintained by NodeSource. The PPA have an array of versions of node.js available than the official ubuntu repositories. Node.js v12, v13, v14, and v15 are available. Refer to the NodeSource documentation

  • First, let's install the PPA in order to get access and take advantage of its packages. From your home directory, use curl to retrieve the installation script for your preferred version, making sure to replace 14.x with your preferred version string. It's recommended to install LTS versions of any software.
$ cd ~
$ sudo apt-get install software-properties-common
$ curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
  • After the above, action the PPA will be added to your configuration and your local package cache. It will be updated automatically giving you liberty now to install the Node.js package:
$ sudo apt-get install nodejs or sudo apt-get install -y nodejs
  • Verify that node.js is installed aptly by simply running node with the -v version flag:
$ node -v
  • Output
v14.15.3

NodeSource nodejs package contains both the node binary and npm, so you don’t need to install npm separately.

Congratulations, you have successfully installed Node.js and npm using apt and the NodeSource PPA.