Node.js development often starts with having the right tools at your fingertips. One such essential tool is NVM, or Node Version Manager, a versatile and convenient way to manage multiple Node.js versions on the Ubuntu system. In this guide, we will help with the process of how to install NVM on Ubuntu 22.04 Linux system version.
Prerequisites
- Running an Ubuntu system with version 22.04 and shell.
- Log in with a non-root user account with sudo privileges set up.
How To Install NVM on Ubuntu (recommended)
Open the terminal on your Ubuntu system (the prerequisites above must be fulfilled). The initial step should be updating the package manager to ensure that is up-to-date by running the following command:
sudo apt update
Then install curl or another tool for getting packages:
sudo apt install curl
Then use cURL or Wget to download the NVM installation script. For cURL:
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
The environment entry for the currently logged user will be created. To apply the changes, you need to type:
source ~/.bashrc
or simply close the terminal and reopen it again. After this, you should be able to use NVM on your Ubuntu machine.
Verify Installation:
Confirm that NVM is successfully installed by checking its version:
nvm –version
The output should be an installed version of NVM.
Installing Node using NVM
As we have NVM already installed, the next step will be the installation of Node.js. We will use the already-installed NVM and install the latest version of Node.
nvm install node
If you wish to download a specific version, just use:
nvm install 18.18.2
Then just replace 18.18.2 with your desired version of node (a list of all available versions can be found at this link).
nvm install lts/gallium
You can also install a version based on its alias. Just replace gallium with your desired version of node.
Working with NVM
As the NVM enables us to install and configure several versions of Node in your working environment, we will shortly explain how to use it.
To check all the installed versions of the node for the current user:
nvm ls
When you want to switch to a different version that is already installed:
nvm use 18.18.2
To get all available node.js versions that can be installed:
nvm ls-remote
You don’t need to change the version for each script. Node also has the possibility to choose the desired version for each script individually:
nvm exec 18.18.2 script.js
Uninstalling and removal
As you can install several versions of Node.js, if you don’t need some of them, you can simply uninstall them by typing the following command:
nvm uninstall 18.18.2
Version 18.18.2 will then be uninstalled from your environment.
Node installation validation
You can check if the Node install was successful using the command:
node -v
The output should be the current version of Node installed.
Frequently Asked Questions (FAQs)
How do I update my NVM version of Node.js?
If you want to update to the newer version of Node.js using NVM just type the following command:
nvm install <newer version>
Should I install nvm before node?
Yes, we recommend first installing NVM and then using it to install Node.js
How to check the version of nvm installed?
To check the installed version of nvm, just use the following command:
nvm –version
How to check the version of Node.js installed?
To check the installed version of Node.js, just use the following command:
node -v
Wrapping Up
Congratulations! This guide on how to install NVM on Ubuntu 22.04 Linux is finished. You’ve successfully installed NVM on your Ubuntu system, unlocking the flexibility to manage and switch between different Node.js versions effortlessly. You have now the possibility to install node.js and many others. When you are done, boots your attitude with some discounts.