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

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.

Recommended Linux Ubuntu Tutorials

AuthorDevendra Dode

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 *