DEV Community

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

Posted on • Edited on

4

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

Introduction

JavaScript server side programming is supported by Node.js. It's constructed using the JavaScript V8 engine from Google Chrome. It enables programmers to make swift, greatly scalable, and data-intensive applications.

The installation of nodejs on Ubuntu 20.04 and later is demonstrated in this guide. To install particular versions of the nodejs, we will install it using the apt PPA software repository.

Using apt and the NodeSource PPA to install node.js

A personal package archive (PPA), which is actively handled and maintained by NodeSource, can be used to upgrade or install a new type of nodejs version. Nodejs versions are accessible in a wider variety on the PPA than in the official Ubuntu repositories. There are nodejs versions 12, 13, 14, 15, 16, and 18 available. Take a look at the NodeSource documentation for more information.

  • Installing the PPA will let you to access and use its packages, so let's do that first. Use curl to get the installation script for your choice version from your home directory, being sure to replace 16.x with your chosen version string. Any software should be installed in LTS versions.
$ cd ~
$ curl -sL https://deb.nodesource.com/setup_16.x -o nodesource_setup.sh
Enter fullscreen mode Exit fullscreen mode
  • The PPA will be added to your configuration and local package cache after you take the aforementioned action. You'll now have the freedom to install the nodejs package because it will be updated automatically:
$ sudo apt install nodejs
Enter fullscreen mode Exit fullscreen mode
  • Run node with the -v version flag to ensure that nodejs is properly installed:
$ node -v
Enter fullscreen mode Exit fullscreen mode
  • Output
v16.16.0
Enter fullscreen mode Exit fullscreen mode

Npm does not need to be installed individually because it is included in the NodeSource nodejs package together with the node binary.

With apt and the NodeSource PPA, you have successfully installed nodejs and npm.

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (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.

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay