How to Install and Use Node JS on Ubuntu 22.04?
Jul 14, 2022 . Admin
Hi Guys,
I will explain step by step tutorial Using commands to Install Node JS on Ubuntu 22.04. if you have question about Ubuntu 22.04 on Install and Use Node JS then I will give simple example with solution. Here you will learn Install and Configure Node JS on Ubuntu 22.04. you will learn Linux Ubuntu 22.04 on Install Node JS.
You can use this post for ubuntu 14.04, ubuntu 16.04, ubuntu 18.4, ubuntu 20.04, ubuntu 21 and ubuntu 22.04 versions.
Follow the 3 easy ways to install and use node js
solution 1: Installation of Node.js using the default repository of Ubuntu 22.04
solution 2: Installation of the Node.js using the PPA repository
solution 3: Installation of the Node.js using the NVM
How to use the Node.js on Ubuntu 22.04
solution 1: Installation of Node.js using the default repository of Ubuntu 22.04Run the following command at the command prompt to install Node JS:
$ sudo apt install nodejs -y
The node will check the JS version using the following command:
$ nodejs --version
If we found any error while installation of node js on ubuntu, can be resolve by fixing the broken packages:
$ sudo apt --fix-broken installsolution 2: Installation of the Node.js using the PPA repository
Run the following command at a command prompt to install node js:
$ curl -fsSL https://deb.nodesource.com/setup_17.x | sudo -E bash - sudo apt-get install -y nodejs
Install it using the apt package manager:
$ sudo apt install nodejs
Again will confirm the installation of the Node.js by displaying its version:
$ nodejs --versionsolution 3: Installation of the Node.js using the NVM
Run the following command at a command prompt to install any specific version of Node.js:
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Now we will run the following commands:
$ export NVM_DIR="$HOME/.nvm" $ [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" $ [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
Let's check the version of NVM installed:
$ nvm --version
Display the list of all versions of the Node.js which are available on NVM:
$ nvm list-remote
We can install the latest version using the command:
$ nvm install node
We will validate the installation by displaying the installed version of Node.js:
$ node --versionHow to use the Node.js on Ubuntu 22.04
Run the following command at the command prompt to create the text file:
$ 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))
To run the output of the above code, we will use the command:
$ node MyJScode.js