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:
Step 2: Install Node.js on Ubuntu
Once the system libraries are updated, install Node.js on Ubuntu by running the given command:
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:
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:
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:
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:
Remember to replace the 20 with your desired version:
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:
Step 4: Verify Node.js Installation
Once the Node.js is installed via NodeSource, execute the mentioned command to verify the version:
You can also check the NPM version installed along with Node.js by using the following command:
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.
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:
Step 2: Save Changes
Once the NVM is installed on Ubuntu, run the given command to save the changes to the system:
Step 3: Install Node.js on Ubuntu
Before installing Node.js, first list down the already installed Node.js versions through the mentioned command:
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:
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:
After installing the latest Node.js version, let’s get the Node.js versions again by running the below command:
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:
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.
Execute the mentioned command to install the stable release of the Node.js package using Snap:
Check whether the Node.js was installed through Snap or not by running the below command:
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:
To remove the dependencies related to the Node.js package, run the mentioned command:
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:
Step 2: Deactivate NVM
Once you retrieved the version number of the Node.js, now deactivate NVM by running the given command:
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:
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:
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.
By day, I am an engineer and researcher, building bridges and figuring out how the universe works. But when the clock strikes five, I turn into a wordsmith!
I write about my adventures on my blog, sharing tips and tricks to help others join the tech fun. I have worked on Raspberry Pi, Ubuntu, Debian, and Laptops. Right now, I have accepted the challenge of working on the Kali Linux system, and with my vast expertise in Linux systems, I will help users overcome the challenges through my blogs.