DEV Community

loading...
Cover image for A step-by-step guide to installing Node.js on Ubuntu

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

Kater Akeren
Result-oriented Software Engineer and excellent team player with expertise in building secured and scalable applications. Lover of open source.
・2 min read

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 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 ~
$ curl -sL https://deb.nodesource.com/setup_14.x -o nodesource_setup.sh
Enter fullscreen mode Exit fullscreen mode
  • 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 install nodejs
Enter fullscreen mode Exit fullscreen mode
  • Verify that node.js is installed aptly by simply running node with the -v version flag:
$ node -v
Enter fullscreen mode Exit fullscreen mode
  • Output
v14.15.3
Enter fullscreen mode Exit fullscreen mode

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.

Discussion (1)

Collapse
peter279k profile image
peter279k

I also recommend using the nvm to install and manage multiple Node.js versions.

It's easy to manage multiple Node.js versions and it's proper for the purpose to test some packages with different Node.js versions.