How to Install Node js 18.x|16.x on Ubuntu 22.04

[ad_1]

If you want to install 16.x or 18.x version of node.js in your Ubuntu system, for this you can use curl -sL https://deb.nodesource.com/setup_16.x, 18.x -o nodesource_setup.sh and sudo apt install nodejs command.

Ezoic

How to Install Node.js 18.x|16.x on Ubuntu 22.04

Here are the simple ways to install and use node.js 16.x or 18.x on Linux Ubuntu 22.04:

  • #1. Installing Node.js 16.x using the PPA repository on Ubuntu 22.04
  • #2. Installing Node.js 18.x using the PPA repository on Ubuntu 22.04

Before starting the installation, open your terminal or command line. And then choose to install the node.js version as per your requirement.

Ezoic

#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:

Ezoic

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

Once installed, to confirm the installation version, use this command:

Ezoic

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, for this you can use the curl command:

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:

Ezoic

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

Execute the following command on command prompt to create a text file using the nano text editor:

Ezoic

nano MyJScode.js

Now we will 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))

In the above code, we simply assign two values in variable a and b, and add them together to display the output. To run the output of the above code, we will use the command:

node MyJScode.js

Here is the video tutorial for installation node js 18 ubuntu 22.04:

Conclusion

Through this tutorial, you have learned how to install and use of Node.js 16.x or 18.x on Ubuntu 22.04.

Recommended Linux Ubuntu Tutorials

[ad_2]

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

Contact
Jassweb, Rai Chak, Punjab, India. 143518