Node is becoming the first choice of developers for building front-end applications. Also, many developers are using this for building REST API and CRUDs. This programing language is developed by OpenJS Foundation, which runs on Chrome’s v8 engine.
Node.js is available for most modern operating systems including Ubuntu Linux. In this tutorial, we will provide you with 3 methods of installing Node.js on the Ubuntu 22.04 Linux system.
- Install Node.js from Default Apt Repository
- Installing Node.js from Nodesource Repository
- Install Node.js using NVM (Recommended)
Choose one of the below methods to install Node.js on Ubuntu 22.04 Linux system:
Method 1 – Installing Node.js from default Apt Repository
The default Ubuntu 22.04 repository contains an old version of Node.js. Currently, the repositories contain the Node 12.22.9 version.
To install Node.js from default repositories, run:
sudo apt update
sudo apt install nodejs
This will install the available Node.js version in default Ubuntu repositories.
Method 2 – Installing Node.js from NodeSource Repository
First of all, curl must be installed on your system. Then add the NodeSource repository in your system.
sudo apt install curl
curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
You can change the Node version repository by changing the 16 with the required Node.js version (eg: 14, 17, etc)
Then install the Node.js using the Apt package manager.
sudo apt update && sudo apt install nodejs
The above command will install Node.js on Ubuntu 22.04 as per the configured repository version.
The next method is my favorite method of installing Node.js on any Linux system.
Method 3 – Installing Node.Js using NVM
A shell script is available for the installation of nvm on the Ubuntu 22.04 (Jammy Jellyfish) Linux system. Open a terminal on your system or connect a remote system using SSH. Use the following commands to install curl on your system, then run the nvm installer script.
sudo apt install curl
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
The nvm installer script creates an environment entry to the login script of the current user. You can either log out and log in again to load the environment or execute the below command to do the same.
Now you can install any version of Node.js on your system. Also it allows to install multiple Node.js versions on your system. For example, to install Node 16.14.0, type:
nvm install 16.14.0
For the detailed instructions, you can visit the dedicated tutorial for installing NVM on Ubuntu 22.04 Linux system.
The Node.js versions installed with the apt package manager can be removed with the following command.
sudo apt purge nodejs
If the Node is installed with NVM can be removed with the following command.
nvm uninstall 16.14.0
Repeat the above command to remove other versions as well.
In this tutorial, you have learned 3 methods of installing Node.js on the Ubuntu 22.04 LTS Linux system. You can choose any of the above methods for the Node.js installation.
It’s a good practice to always use the latest version or stable version of Node.js. Hope this tutorial is helpful for you.