How to Install node.js on Ubuntu 22.04 LTS

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.

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
1 update

Use below command to install Node.js on Ubuntu 22.04 LTS

sudo apt install nodejs
1 install node js

Once your installation done, verify the installation of node.js using below command,

node –v
1 v node

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
1 install npm

After npm installation complete you can verify npm

npm –version
1 v npm

#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 -
2 bash

You can now install the Node.js package in the same way you did in the previous section:

sudo apt install nodejs
2 install nose js

Verify that the Node.js and npm version on Ubuntu 22.04 LTS

nodejs –version
npm –version
2 v npm node

#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
3 install wget
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.39.0/install.sh | bash
3 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
3 nvm version

You can list all Node.js version that can be installed with NVM using

nvm list-remote
3 nvm list

Install the latest stable version of Node.js

nvm install node version(like v18.15.0)
3 nvm install specific version

You can outlook the different versions you have installed by listing them

nvm list
3 nvm list 2

You can switch between installed versions

nvm use v18.15.0

Once the installation is completed, verify the Node.js version.

node –version
3 verify node

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:

How to Create VPC Network in Google Cloud

About Priti Adkine

I am Priti Adkine working as Software Engineer and having 1+ years of Experience. Likes to share knowledge.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link