Home » How to install Node.js 20 LTS on Ubuntu 22.04 – step-by-step
How to install Node.js 20 LTS on Ubuntu 22.04 – step-by-step

How to install Node.js 20 LTS on Ubuntu 22.04 – step-by-step

Node.js is an open-source, cross-platform JavaScript runtime environment that allows developers to run JavaScript code outside a web browser. The environment is highly efficient in the development of web servers. Node.js is designed, lightweight and efficient using Javascript v8 runtime. In this blog, we will explore How to install Node.js 20 LTS on Ubuntu 22.04.

Installing Node.js 20 on Ubuntu has serval methods:

  1. Installing Node.js Using the Default apt Package Manager.
  2. Installing Node.js Using the PPA Repository.
  3. Installing Node.js using Node Version Manager (NVM).

Method 1:  Installing Node.js Using the Default apt Package Manager.

First, we have to update the APT package in Ubuntu to run this command in your command Prompt:

sudo apt update && sudo apt upgrade

 Install node.js 20 on Ubuntu 1


Second, We have to add a node.js 20 and run this command:

sudo apt install nodejs

Example 2


Third, Check the Node.js version using this command:

Version checker


Method 2: Installing Node.js Using the PPA Repository.

The PPA repository stands for Personal Package Archive. It is a special type of software repository compatible with the Debian-based Linux distribution, including Ubuntu. It allows individual developers and Linux users to create their own repositories with the software they want to distribute to users. Developers package, distribute, and manage PPA repositories, and users install, update, and remove software. PPA repositories provide access to additional software not included in official releases.

Installing Node.js using the PPA repository:

First, We have to install curl in our system to access the PPA repository.

sudo apt install curl

Installing curl image


Second, we have to execute the below command to successfully install the node.js:

sudo apt-get update && sudo apt-get install -y ca-certificates curl gnupg
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
NODE_MAJOR=20
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
sudo apt-get update && sudo apt-get install nodejs -y

Install node.js using curl


Lastly, we have checked the installed node.js version the run this command.

node -v


Method 3: Installing Node.js using Node Version Manager (NVM):

NVM allows you to easily install and switch between different node.js versions on your system. This is useful when you are working on a project that requires a specific node.js version.

With NVM, you can install multiple node.js versions side by side and switch between them based on your requirements.

First, Install the node version manager:

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

Node version manager install


The command download and install NVM in your system. Once NVM installs, you can manage different node.js versions.

To list all versions of node.js, we can use the below command:

source ~/.bashrc
nvm list-remote

NVM version list


Next, we need to scroll down and install the least node.js version using this command:

nvm install v21.6.2

NVM install node.js version


and then check the node version in the system:

node -v

node vrsion image


Conclusion:


Node.js is a useful tool for running JavaScript on a server. It’s lightweight, works on different systems, and builds fast and scalable server applications. In this blog, we discuss how to install Node.js 20 LTS on Ubuntu 22.04. In this, we have used 3 different methods to install node.js in Ubuntu. I hope this blog finds you well knowledgeable and that you can learn more about this in this blog. If you have installed node.js 18 in Ubuntu, check this blog.

FAQ:

1. How to install node JS in Ubuntu 22.04 using nvm?

To install Node.js in Ubuntu 22.04 using nvm, follow these steps:

1. Install NVM Using this command:

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


2. Installing NVM then we have to install specific Node.js Version 16.15.0 using this command:

nvm install v16.15.0


3. To set the installed version as a default version, use this command:

nvm alias default 16.15.0


4. Check the Node.js Version using this command:

node -v


This command shows the output in your command prompt 16.15.0.

2. How to install nodejs LTS version in Ubuntu?

To install the LTS version of Node.js on Ubuntu, you can follow these steps:

1. Update your system: Installing node.js first update system packages using this command:

sudo apt update
sudo apt upgrade -y


2. Install CURL: First, we have to install curl using this command:

sudo apt install curl -y


3. Install NVM: Install NVM using this command:

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


4. Activate NVM: Activate NVM using this command:

source ~/.bashrc


5. Install the latest LTS version of Node.js: Install the latest version using this command:

nvm install --lts


6. Make the default LTS version NVM: Set the default version of the node.js using this command:

nvm alias default <LTS_VERSION>


7. Confirm that Node.js was installed: Check the Node.js version using this command

node -v
npm -v


Shows the Node.js version you are installing.

More Reading

Post navigation

Leave a Comment

Leave a Reply

Your email address will not be published. Required fields are marked *