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

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

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.

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.

#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

Once installed, 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, 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:

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:

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

AuthorAdmin

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

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