Open In App

How to Install NVM on Ubuntu 22.04

Last Updated : 11 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Whether you are developing a web application, working with a Node.js-based project, or learning Node.js in general, NVM makes it easier to work with your Node.js environments in Ubuntu. In essence, NVM (Node Version Manager) is a useful tool for working with multiple versions of Node.js on your computer. Using NVM, you can easily install, switch between, and manage various Node.js versions for your development projects.

Prerequisites to Install NVM on Ubuntu

  • Active Ubuntu 22.04
  • apt package manager must be installed in your Ubuntu.
  • curl command-line interface must be installed.
  • Ensure that you have sudo or administrative privileges to execute the commands required.

Step 1: Update Package Repository

Before installing NVM, it's essential to ensure that your system's package repository is up-to-date. Open a terminal window by pressing Ctrl + Alt + T and execute the following command:

Before installing NVM, make sure that the package repository on your system is updated. In a terminal window, press Ctrl + Alt + T and then run the command:

sudo apt-get update
sudo-update
Updating package repository


Enter your password when prompted, and wait for the process to complete. This command updates the local package index to reflect the latest changes in the repository.

Step 2: Install Prerequisites

NVM comes with certain prerequisites that must be installed on your system prior to proceeding with the installation. To install the prerequisites, you can enter the following command in the terminal:

sudo apt install curl
2024-03-15_12-43_1
installing curl in ubuntu

The above command installs the curl package, and it is utilized in downloading NVM and other resources.

Step 3: Download and Install NVM on Ubuntu

Once the prerequisites are installed, you may now download and install NVM. Run the following curl command in the terminal:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
2024-03-15_12-45
installing nvm on ubuntu

The above command downloads the NVM installation script directly from the official GitHub repository and pipes it into the bash shell to run it. Make sure that you update v0.39.1 with the current version at the time of your installation.

After the installation script is complete, you may need to close and re-open your terminal window or run source ~/.bashrc to apply changes to your current shell session.

Step 4: Verify NVM Installation on Ubuntu

To ensure that NVM is installed correctly on your system, you can run the following command:

nvm --version
2024-03-15_12-46
Verify nvm installation

If NVM has been installed properly, the above command will display the version of NVM installed.

Step 5: Install Node.js Using NVM

Individual versions of Node.js can be installed now using NVM installed. To install, for example, the latest LTS version of Node.js, run the following command:

nvm install --lts
2024-03-15_12-48
nstalling node.js using nvm in Ubuntu

The command will download and install the latest LTS version of Node.js.

Step 6: Switch Between Node.js Versions

One of the most significant things about NVM is that you can easily switch between versions of Node.js. To show you all the versions of Node.js installed on your system, you can use the following command:

nvm ls
2024-03-15_12-49
listing node.js version in Ubuntu

This command will display a list of installed Node.js versions, indicating which version is currently active.

To switch to a specific Node.js version, you can use the following command:

nvm use <version>

Replace <version> with the desired Node.js version, such as 14.17.0 or lts.

Conclusion

Installing the NVM on Ubuntu 22.04 is allows us to easily manage multiple versions of Node.js on the system which provides the flexibility and convenience for to your development projects. By following the steps outlined in this guide, you should be able to install NVM, verify the installation, install Node.js versions, and switch between them effortlessly. NVM simplifies the process of managing Node.js versions and ensures compatibility with your projects' requirements.


Next Article
Article Tags :

Similar Reads