How to install Node JS in ubuntu 20.04

In this guide, you will learn how to install/configure Node JS and npm on ubuntu 20.04 and write your first program.

Node JS install ubuntu 20.04
Node JS install ubuntu 20.04

Node JS is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.JS is perfect for developing web applications, real-time applications, and APIs.

This guide walks you through the the installation and configuration of Node.JS on Ubuntu 20.04. In the next section, We will discuss some of the most popular Node.JS modules and tools you can use to create your next project. Stay tuned for that.

Let's get started!

Prerequisites

Ensure you have the following to follow along.

  • Ubuntu 20.04 installed on your system
  • User with sudo privileges
  • Internet connection
  • Access to the terminal.

Updating the apt manager

We will use the apt package manager to install Node JS.

First, Update the apt package index with the following command:

sudo apt update

The next thing is to upgrade the repository. Run the following command:

sudo apt upgrade -y

Node JS installation

We now install Node JS and npm (Node JS package manager) with the following command.

sudo apt install nodejs npm

Press "y" to continue when prompted.

This command will install Node and the npm package manager, which we will use to install Node JS modules.

Verify the Node JS version installed

After the installation, verify that Node.JS and npm are successfully installed by running the following commands:

node -v

output:

v10.19.0

The node version installed in my system is v10.19.0. Yours will probably differ, but this confirms that Node is successfully installed on your machine.

You can verify that npm is installed on your system with the following command.

npm -v

output:

6.14.4

Working with Node JS

Now that we have installed Node JS on our system, we can start writing our first program.

Create a new file named geekbits.js using your favorite text editor and add the following code:

console.log('Hello, world!');

Save the file then exit the editor. Run the program with the following command:

node geekbits.js

Make sure you are in the right directory i.e., where the file is saved.

Output:

Hello, World!

The output "Hello, world!" should be printed on the console.

Salute! You have written your first Node JS program

There are many popular modules and tools available for Node.JS development. So stay tuned for this tutorial.

Conclusion

In this guide, we have successfully installed and configured Node together with its package manager (npm) on Ubuntu 20.04.

If you enjoy our content, please consider buying us a coffee to support our work:

Table of Contents
Great! Next, complete checkout for full access to GeekBits.
Welcome back! You've successfully signed in.
You've successfully subscribed to GeekBits.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info has been updated.
Your billing was not updated.