How to Install Node.js and npm on Ubuntu 22.04

How to Install Node.js and npm on Ubuntu 22.04

Hello friends, welcome to Inet70 today. I can guide you on how to install Node.js and npm on Ubuntu operating system. npm stands for Node.js Package Manager. This type of mode.js is used for making web applications in Linux servers.

Table of Contents

You can host your web application on mode.js and publish it with Nginx or Apache server. Node.js is best compatible with Nginx compared to Apache web server. Node.js and npm are free and available for Linux. This service is used to host CMS (Content Management Service) like WordPress, Ghost, and more. Now we can start the Node.js and npm installation process on Ubuntu.

Install Node.js and npm on Ubuntu

There are 3 ways to install Node.js and npm on Ubuntu operating system. You can follow any way to install this. All the methods are best and easy to use. Our first step is to update and upgrade all Ubuntu packages.

				
					sudo apt update
sudo apt upgrade -y
				

Now follow all the ways to start Node.js and npm installation process.

Install Node.js and NPM Directly

This is a direct method to install Node.js and npm on Ubuntu. In this process, there is no need for any type of external repo to install npm. You can just open the terminal and put the following command to start Node.js and npm installation process.

				
					sudo apt install nodejs npm

				

install node.js with node source repo

After putting this command, Node.js and npm installation process will start on your Ubuntu server. Now check the current version of both packages.

				
					node --version
npm --version

				

In this method, you cannot install the specific version of the Node.js and npm packages. Therefore, I cannot recommend this method to you in your Ubuntu operating system.

Uninstall Node.js and NPM

This package’s uninstallation process is too easy. If you don’t know which Node.js and npm version to follow the given commands to remove it.

				
					sudo apt remove nodejs npm
sudo apt autoremove
sudo apt clean

				

Now your system is clean. Now you can try the second method of installation, which means installing Node.js and npm with the Github repository.

Install Node.js and npm with Short Node Source Repository

This method is best responsible. Using this method, you can install the latest version of Node.js package in Ubuntu operating system. Using this method, you can install two types of Node.js packages. You can install Node.js current and Node.js LTS plan. You can follow all my steps to install on your Ubuntu system.

Here you can follow the given steps to install Node.js latest version and Node.js LTS version from the given commands.

Install Latest Version with Following Communication Version of Node.js Packages with Node Source File Install with curl. First, you can install curl in Ubuntu package.

				
					sudo apt install curl

				

Here Node.js latest version is 20 at this time. You can follow the given command to download the source list file.

				
					curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
				

install node.js with node source repo

Now you can install Node.js today version 20 package with the following command.

				
					sudo apt-get install -y nodejs

				

nodejs install

If you have an interest in using the LTS of means Long-Term-Support installation process with given commands:

				
					curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs

				

After following this step, your computer system is ready to use Node.js long-term support.

Remove Node.js

If you need to remove the following Node.js version, then you can follow the given step to remove it from the Ubuntu operating system.

				
					sudo apt purge nodejs
sudo apt autoremove

				

After following both commands, you have successfully removed Node.js, but their Node source list file is stored in the source directory. Please follow the following command to remove the Node.js source list.

				
					sudo rm -r /etc/apt/sources.list.d/nodesource.list
				

Now we can jump to the LTS one method to install Node.js and npm on Ubuntu.

Install Node.js and npm using NVM

This is the last one and fully customized method to install Node.js. It is a 100% trusted method. This service provides any Node.js version on your Ubuntu device. NVM stands for Node Version Manager. Follow the given command to download the NVM bash file and install it on your Ubuntu operating system.

				
					curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
source ~/.bashrc

				

Install Node.js with NVM

After putting this command, you can download and install NVM successfully.

After following all commands, you have successfully installed NVM on your system. Now you can follow the given commands to show which Node.js version you need to install on your system.

				
					nvm ls-remote

				

Here all NVM version lists are available. You can put the version name at the last of the Node version.

				
					nvm install node 20.5.1

				

After putting this command, you can install a specific version of the Node.js version. Thanks for Visit My Blog.