Ronalds Vilciņš

Digital Media & Code

Installing Node.js on Ubuntu 20.04

Node.js is a powerful JavaScript runtime environment that allows you to build scalable and efficient web applications. If you’re using Ubuntu 20.04 as your operating system, this tutorial will guide you through the process of installing Node.js on your machine. By following these steps, you’ll be ready to start developing applications with Node.js in no time.

Step 1: Update system packages

Before we begin, let’s ensure that our system is up to date by running the following commands:

sudo apt update
sudo apt upgrade -y

Step 2: Install Node.js using the NodeSource repository

NodeSource provides a reliable repository for installing Node.js. Execute the following commands to add the NodeSource repository to your system:

curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -

Step 3: Install Node.js

Once the repository is added, run the following command to install Node.js:

sudo apt install -y nodejs

Step 4: Check the installation

To verify that Node.js and npm (Node Package Manager) have been successfully installed, run the following commands:

node --version
npm --version

Step 5: Managing Node.js versions with nvm (optional)

If you want to manage multiple Node.js versions on your system, you can use nvm (Node Version Manager). Here’s how you can install nvm:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash

After the installation, close and reopen your terminal, or run the following command:

source ~/.bashrc

To install the latest Node.js version, use the following command:

nvm install node

You can also install a specific version of Node.js using the following command:

nvm install <desired_version>

Congratulations! You have successfully installed Node.js on your Ubuntu 20.04 machine. You are now ready to start building powerful web applications with Node.js. Remember to keep your Node.js installation up to date using the package manager or nvm, depending on your preference.