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 on Ubuntu 22.04 LTS from default repository

Before installing,Lets update and upgrade System Packages

sudo apt update
How to Install Node.js on Ubuntu 22.04 LTS 1

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

sudo apt install nodejs
How to Install Node.js on Ubuntu 22.04 LTS 2

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

node –v
How to Install Node.js on Ubuntu 22.04 LTS 3

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
How to Install Node.js on Ubuntu 22.04 LTS 4

After npm installation complete you can verify npm

npm –version
How to Install Node.js on Ubuntu 22.04 LTS 5

#2:Installing Node.js and npm on Ubuntu 22.04 LTS 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 -
How to Install Node.js on Ubuntu 22.04 LTS 6

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

sudo apt install nodejs
How to Install Node.js on Ubuntu 22.04 LTS 7

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

nodejs –version
npm –version
How to Install Node.js on Ubuntu 22.04 LTS 8

#3:Installation of Nodejs on Ubuntu 22.04 LTS 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
How to Install Node.js on Ubuntu 22.04 LTS 9
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.39.0/install.sh | bash
How to Install Node.js on Ubuntu 22.04 LTS 10

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
How to Install Node.js on Ubuntu 22.04 LTS 11

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

nvm list-remote
How to Install Node.js on Ubuntu 22.04 LTS 12

Install the latest stable version of Node.js

nvm install node version(like v18.15.0)
How to Install Node.js on Ubuntu 22.04 LTS 13

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

nvm list
How to Install Node.js on Ubuntu 22.04 LTS 14

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 Install Node.js on Ubuntu 22.04 LTS 15

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 nvm version using below command

nvm deactivate

In this Article we have covered 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 22.04 LTS. 

Related Articles:

How to Install Latest Node.js and NPM on Ubuntu 19.04,18.04/16.04 LTS

How to Install Angular CLI on Ubuntu 18.04/16.04 LTS

How to Install node.js on Mac OS How to Install Node.js on Windows 10

How to Install Node.js and NPM on Ubuntu 20.04 LTS

FOSS TechNix

FOSS TechNix (Free,Open Source Software's and Technology Nix*) founded in 2019 is a community platform where you can find How-to Guides, articles for DevOps Tools,Linux and Databases.

Leave a Comment

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

Share via
Copy link
Powered by Social Snap