In this tutorial, you will learn how to install node js 18.x or 16.x on ubuntu 22.04 using curl -sL https://deb.nodesource.com/setup_16.x, 18.x -o nodesource_setup.sh
and sudo apt install nodejs
command.
How to Install Node.js 18.x|16.x on Ubuntu 22.04?
Here are the simple ways for that:
#1. Installing Node.js 16.x using the PPA repository on Ubuntu 22.04
Installing the version of Node JS 16.x requires downloading the repository from nodesource
, for this, you can use the curl command:
curl -sL https://deb.nodesource.com/setup_16.x -o nodesource_setup.sh
To start the installation process of node.js 16.x version, you can use this command:
sudo bash nodesource_setup.sh
Now The PPA package of Node.js 16.x has been added to your Ubuntu system, now you can install the Node.js 16.x version into your system using the command:
$ sudo apt install nodejs
To confirm the installation version, use this command:
$ nodejs --version
#2. Installing Node.js 18.x using the PPA repository on Ubuntu 22.04
Installing the version of Node JS 18.x requires downloading the repository from nodesource:
curl -sL https://deb.nodesource.com/setup_18.x -o nodesource_setup.sh
To start the installation process of node.js 18.x version, you can use this command:
sudo bash nodesource_setup.sh
Now The PPA package of Node.js 18.x has been added to your Ubuntu system, now you can install the Node.js 18.x version into your system using the command:
$ sudo apt install nodejs
Once installed, to confirm the installation version, use this command:
$ nodejs --version
How to use the Node.js on Ubuntu 22.04
Run the following command on the command line to create a text file using the nano
command:
$ nano MyJScode.js
Now, type the code for the simple addition of the two numbers by using the Javascript:
function add(a,b) { return a+b } console.log(add(4, 6))
To run the the following command to see the output on command line:
$ node MyJScode.js
Conclusion
Through this tutorial, you have learned how to install and use of Node.js 16.x or 18.x on Ubuntu 22.04.