In this article we are going to learn How to install node.js on Ubuntu 22.04 LTS and and any other cloud platform like Azure, EC2, Compute Engine, How to Uninstall Node.js from Ubuntu 22.04 LTS.
Table of Contents
What is Node.js ?
Node.js is free and an open-source cross-platform JavaScript run-time environment that allows server-side execution of JavaScript code. It is used in developing web and networking applications.
NPM(Node Package Manager) is command line tool for Node.js packages that installs, updates and uninstall packages in your projects.We don’t have install npm separately it is includes with Node.js installation.
Prerequisites
- Ubuntu 22.04 LTS
- SSH access with sudo privileges
- Firewall Port: 3000
How to Install Node.js on Ubuntu 22.04 LTS
There are 3 different ways installation of node.js on Ubuntu 22.04 LTS.
- Installation of Node.js on Ubuntu 22.04 LTS from default repository
- Installing Node.js and npm on Ubuntu 22.04 LTS from NodeSource
- Installation of Nodejs on Ubuntu 22.04 LTS using Node version manager
#1:Installation of Node.js from default repository.
Before installing,Lets update and upgrade System Packages
sudo apt update
Use below command to install Node.js on Ubuntu 22.04 LTS
sudo apt install nodejs
Once your installation done, verify the installation of node.js using below command,
node –v
In most cases, you’ll also want to install npm, the Node.js package manager. You can do this by installing the npm package with apt
sudo apt install npm
After npm installation complete you can verify npm
npm –version
#2:Installing Node.js and npm from NodeSource
Firstly you have to install curl using below command
sudo apt install curl
Download and run the Node.js installation script, Visit the official node.js page to download current and LTS version.
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
You can now install the Node.js package in the same way you did in the previous section:
sudo apt install nodejs
Verify that the Node.js and npm version on Ubuntu 22.04 LTS
nodejs –version
npm –version
#3:Installation of Nodejs using Node version manager
Another way of installing Node.js that is particularly flexible is to use nvm, the Node Version Manager. NVM is a script that allows you to manage multiple version of Node.js.
Firstly, you need to download and install NVM using wget
sudo apt-get install wget
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.39.0/install.sh | bash
Allow the NVM script to run from your user’s bash profile
source ~/.profile
verify the NVM version on Ubuntu 22.04 LTS
nvm --version
You can list all Node.js version that can be installed with NVM using
nvm list-remote
Install the latest stable version of Node.js
nvm install node version(like v18.15.0)
You can outlook the different versions you have installed by listing them
nvm list
You can switch between installed versions
nvm use v18.15.0
Once the installation is completed, verify the Node.js version.
node –version
How to Uninstall Node.js from Ubuntu 22.04 LTS ?
Remove node.js using following command
sudo apt remove nodejs
Remove using NVM
Firstly, you have to check recent active version using
nvm current
Now deactivate the version using
nvm deactivate
In this Article we have learn How to install node.js on Ubuntu 22.04 LTS.
Conclusion:
In this article, We have performed ,How to Install Node.js on Ubuntu 22.04 LTS, Checked Node.js and NPM version and performed to uninstall node.js and NPM from ubuntu.
Related Articles: