How to install node. Js on ubuntu 22. 04

How to Install Node.js on Ubuntu 22.04

Node.js is an open-source default runtime environment for JavaScript that is used to develop and deploy server-side web applications on Ubuntu. It is built upon Chrome’s V8 engine, which is superfast and completes the code quickly. Node.js empowers JavaScript to run its code outside the internet browser. Node.js comes with cross-platform support and can be installed on Ubuntu. Let’s dig in and install Node.js on Ubuntu by following this article.

Outline:

How to Install Node.js on Ubuntu 22.04

You can install Node.js on Ubuntu using:

Method 1: Install Node.js on Ubuntu 22.04 Using apt Package Manager

Ubuntu’s official repository contains the Node.js package that allows you to quickly install the package from the apt package manager. But, it does not guarantee you to install the updated version of Node.js.

Check the following steps to install Node.js on Ubuntu 22.04.

Step 1: Update System Repositories

Before installing Node.js on Ubuntu, it is necessary to update system packages by running the below-mentioned command:

sudo apt update

How to install node. Js on ubuntu 22. 04 1

Step 2: Install Node.js on Ubuntu

Once the system libraries are updated, install Node.js on Ubuntu by running the given command:

sudo apt install nodejs -y

How to install node. Js on ubuntu 22. 04 2

Step 3: Check Node.js Version

You can verify the Node.js version on Ubuntu installed through the apt package manager by running the below-given command:

node –version

How to install node. Js on ubuntu 22. 04 3

Step 4: Install NPM on Ubuntu

Alongside Node.js it is necessary to install the NPM (Node Package Manager) for the better management of Node.js. To install NPM on Ubuntu, run the mentioned command:

sudo apt install npm -y

How to install node. Js on ubuntu 22. 04 4

Method 2: Install Node.js on Ubuntu 22.04 Through NodeSource (PPA)

The NodeSource is the third-party repository of Node.js containing multiple Node.js versions. Users can install Node.js on Ubuntu via NodeSource. However, the NodeSource repository does not come pre-added on Ubuntu. To add NodeSource (PPA) to the system the curl command-line tool is used. Check the following steps to install Node.js on Ubuntu 22.04 using the NodeSource PPA repository.

Step 1: Install curl on Ubuntu

Before installing Node.js, it is necessary to add the NodeSource repository on Ubuntu, for that we first need to install the curl command line utility using the following command:

sudo apt install curl

How to install node. Js on ubuntu 22. 04 5

Step 2: Add NodeSource Repository

Once the curl utility is installed, let’s determine the latest Node.js version by navigating to the NodeSource web page. By the time of writing this guide, NodeSource has the 20.x version. We copied the repository link and provided it to the curl command to add the NodeSource repository to the system, as shown below:

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

Remember to replace the 20 with your desired version:

How to install node. Js on ubuntu 22. 04 6

Step 3: Install Node.js on Ubuntu

Once the NodeSource repository is added to the Ubuntu system, run the below command to install Node.js on Ubuntu through the apt command, as shown below:

sudo apt install nodejs -y

How to install node. Js on ubuntu 22. 04 7

Step 4: Verify Node.js Installation

Once the Node.js is installed via NodeSource, execute the mentioned command to verify the version:

nodejs –version

How to install node. Js on ubuntu 22. 04 8

You can also check the NPM version installed along with Node.js by using the following command:

npm –version

How to install node. Js on ubuntu 22. 04 9

Method 3: Install Node.js on Ubuntu 22.04 Through Node Version Manager (NVM)

Another alternate method to install Node.js on Ubuntu is using the NVM “Node Version Manager”. NVM utility allows the management of the different versions of Node.js on Ubuntu. It comes up with various Node.js versions and gives the freedom to the user to install and use any version of Node.js on Ubuntu.

Check the following steps to install Node.js on Ubuntu through NVM.

See also  Ways to List All Available Commands and Aliases in Linux

Step 1: Install NVM on Ubuntu

Before installing NVM, first, visit the GitHub link to verify the latest version. Once the latest version is verified copy its link and provide the curl command to install NVM on Ubuntu, as shown below:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

How to install node. Js on ubuntu 22. 04 10

Step 2: Save Changes

Once the NVM is installed on Ubuntu, run the given command to save the changes to the system:

Sponsored
source ~/.bashrc

How to install node. Js on ubuntu 22. 04 11

Step 3: Install Node.js on Ubuntu

Before installing Node.js, first list down the already installed Node.js versions through the mentioned command:

nvm list

How to install node. Js on ubuntu 22. 04 12

According to the above output, there are no Node.js versions installed on the system.

Let’s get the list of Node.js versions we can install on Ubuntu by running the mentioned command:

nvm list-remote

How to install node. Js on ubuntu 22. 04 13

How to install node. Js on ubuntu 22. 04 14

There are numerous Node.js versions we can install on Ubuntu.

Let’s install the latest Node.js version on Ubuntu by specifying the version number to the install command alongside the nvm command:

nvm install v20.11.1

How to install node. Js on ubuntu 22. 04 15

After installing the latest Node.js version, let’s get the Node.js versions again by running the below command:

nvm list

How to install node. Js on ubuntu 22. 04 16

From the above output, we can see that the latest Node.js version is installed and listed.

Step 4: Verify Node.js Installation

Once you have installed the Node.js package using NVM, place the –version flag alongside the node command to verify whether you have installed the latest version or not:

node –version

How to install node. Js on ubuntu 22. 04 17

Method 4: Install Node.js on Ubuntu 22.04 Through Snap

Ubuntu users can also install the Node.js package via the Snap package manager. Snap is an all-in-one package that consists of all the dependencies of a specified package. One major flex of Snap is that it installs the applications quickly with a single command. For instance, let’s install Node.js on Ubuntu 22.04 using the Snap package manager.

See also  How To Check Running Process in Ubuntu

Execute the mentioned command to install the stable release of the Node.js package using Snap:

sudo snap install node –classic

How to install node. Js on ubuntu 22. 04 18

Check whether the Node.js was installed through Snap or not by running the below command:

node –version

How to install node. Js on ubuntu 22. 04 19

How to Uninstall Node.js from Ubuntu 22.04

These are the methods through which you can remove Node.js from Ubuntu:

Method 1: Remove Node.js from Ubuntu Using apt Package Manager

The method to uninstall Node.js through apt is the same as installing the Node.js on Ubuntu, except for the remove command. To remove the Node.js from Ubuntu, execute the mentioned command:

sudo apt remove nodejs -y

How to install node. Js on ubuntu 22. 04 20

To remove the dependencies related to the Node.js package, run the mentioned command:

sudo apt autoremove nodejs -y

Method 2: Remove Node.js from Ubuntu Using NVM

Check the following steps to remove Node.js from Ubuntu using NVM.

Step 1: Check the Current NVM Version

To remove Node.js using NVM, you need to provide the version number to the nvm uninstall command. So to know the version currently installed on Ubuntu execute the below command:

nvm current

How to install node. Js on ubuntu 22. 04 21

Step 2: Deactivate NVM

Once you retrieved the version number of the Node.js, now deactivate NVM by running the given command:

nvm deactivate

How to install node. Js on ubuntu 22. 04 22

Step 3: Uninstall NVM

After deactivating NVM, you can easily remove Node.js by providing the version number to the nvm uninstall command, as shown below:

nvm uninstall v20.11.1

How to install node. Js on ubuntu 22. 04 23

Method 3: Remove Node.js from Ubuntu Using Snap

To remove Node.js from Ubuntu installed through the Snap package manager, use the below-given command:

sudo snap remove node

How to install node. Js on ubuntu 22. 04 24

Conclusion

Node.js is technically the most sound and trusted JavaScript’s runtime environment. The Node.js can be installed on Ubuntu using apt package manager, NodeSource (PPA) repository, NVM, and Snap package manager. The apt method is simple but doesn’t guarantee installing the latest Node.js version. However, the NodeSource repository and NVM let you install the most recent version of Node.js on Ubuntu. While the Snap method lets you install the Node.js version on Ubuntu in a quick manner.


Discover more from Ubuntu-Server.com

Subscribe to get the latest posts sent to your email.

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply