In this tutorial, you will learn how to install node.js version 21.x Ubuntu 22.04 system using Nodesource, and official repository.
How to Install Node js 21 on Ubuntu 22.04
Here are 2 simple approaches for that:
Approach 1: Installing Node.js 21.x using Nodesource
Start your terminal or command line. And start the installation process.
Run the following nodesource
command to download node js 21.x version:
curl -sL https://deb.nodesource.com/setup_21.x -o nodesource_setup.sh
Run the bash command to extract packages:
sudo bash nodesource_setup.sh
Now The PPA package of Node.js 21.x has been added to your Ubuntu system, now you can install the Node.js 20.x version into your system using the command:
$ sudo apt install nodejs
To confirm the installation version, use this command:
$ nodejs --version
This will print the current version of node.js on the terminal, it looks like this:
v21.0.0
Approach 2: Installing Node.js 20.x using Official Repository
Let’s try second approach:
Type the command sudo apt update on the terminal to update all the packages of your system.
sudo apt update
To install node.js 21.x and latest npm version with the command of apt packager manager, for this, you type the command on the terminal:
sudo apt install nodejs npm -y
When the process is complete on the terminal, if you type the nodejs –version command on the terminal, whatever latest version is installed will show on the terminal:
nodejs--version
This will print the current version of node.js on the terminal, it looks like this:
v21.1.0
Conclusion
That’s it, you have learned how to install the latest version of Node.js 21.x in your ubuntu 22.04.