02 August, 2024

How to Install Node.js on Ubuntu

 Installing Node.js on Ubuntu is a simple procedure that requires only a few steps. Node.js is a popular JavaScript runtime based on Chrome’s V8 JavaScript engine that is commonly used for developing server-side applications. This tutorial will help you through the installation steps. Let’s have a look at the steps for install Node.js on Ubuntu. 

Prerequisites

Before you start, make sure you have the following: 

– A version of Ubuntu, preferred version v18.04 or later

– A user account with sudo privileges.

– Basic Knowledge of Linux terminal commands.

– Internet access. 

Step 1: Update Your System 

Many developers choose Node.js for web application development project, to do that following process needs to be followed. Before installing any new software, it’s always a good practice to update your system’s package index to ensure you have the latest versions of packages and their dependencies. 

Open your terminal and run: 

sudo apt updatesudo apt upgrade -y 

Step 2: Install Node.js on Ubuntu

We’ll go over the two most prevalent methods: utilizing the NodeSource repository and NVM (Node Version Manager). 

Method 1: Using the NodeSource Repository 

  • Add NodeSource Repository 

The easiest way to install Node.js on Ubuntu is using the official Ubuntu repository. To add it, run the following command:

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

This command fetches and executes the NodeSource installation script. 

  • Install Node.js on Ubuntu

After adding the repository, install Node.js using: 

sudo apt install -y nodejs 

This command installs both `node` and `npm` (Node Package Manager). 

  • Verify Installation 

Verify the installation by checking the versions: 

node -v

node -v

npm -v 

nvm -v

You should see output similar to: 

V20.x.x

9.x.x 

Method 2: Using NVM (Node Version Manager) 

  • Install NVM 

NVM is a script-based solution that lets you manage various active Node.js versions. This is very important when you need to move between Node.js versions. 

 

Download and install NVM using the following command: 

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

To start using NVM, you need to source your profile: 

source ~/.bashrc 
  • Install Node.js on Ubuntu with NVM 

With NVM installed, you can install the latest LTS (Long Term Support) version of Node.js: 

nvm install –lts 
  • Verify Installation

Check the installed versions of Node.js and npm: 

node -v
node -v
npm -v
nvm -v

The output should reflect the versions you installed using NVM. 

Step 3: Manage Node.js Versions (Optional) 

If you installed Node.js using NVM, you can easily switch between different versions: 

  • List Installed Versions 

Command:nvm ls 

  • Use a Specific Version 

nvm use 14.17.0 

  • Set Default Version 

nvm alias default 20.19.1 

Conclusion 

Congratulations! You have successfully installed Node.js on your Ubuntu machine. Whether you utilize the NodeSource repository or NVM, you now have an effective tool for developing scalable network applications.

Additional Tips

  • To update Node.js run the following command 

sudo apt update && sudo apt install nodejs

  • To uninstall Node.js, run the following command

sudo apt purge nodejs

  • To install specific version of Node.js using NVM, run the following command

nvm install <version>.  

Profile Picture

Rajan Shah

Technical Manager

Rajan Shah is a Technical Manager at Solution Analysts. He brings almost a decade of experience and a genuine passion for software development to his role. He’s a skilled problem solver with a keen eye for detail, his expertise spans in a diverse range of technologies including Ionic, Angular, Node.js, Flutter, and React Native, PHP, and iOS.

Talk to an EPM Expert

Tell us a bit about your needs and our team will reach out to discuss how we can help.

  • EPM-focused consulting team
  • Experience with U.S. enterprises
  • Expertise across leading EPM platforms
  • Confidential & secure
Trusted by enterprises across indusries
Let's Get In Touch