Open In App

How to Install NVM on Ubuntu 22.04

Last Updated : 15 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

NVM (Node Version Manager) is a handy tool for managing multiple versions of Node.js on your system. With NVM, you can easily install, switch between, and manage different Node.js versions for your development projects. This guide will walk you through the step-by-step process of installing NVM on Ubuntu 22.04, covering each aspect in detail with examples and explanations.

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:

sudo apt-get update
Updating package repository

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 requires some dependencies to be installed on your system before you can proceed with the installation. Run the following command in the terminal to install these prerequisites:

sudo apt install curl
installing curl in ubuntu

installing curl in ubuntu

This command installs the curl package, which is necessary for downloading NVM and other resources.

Step 3: Download and Install NVM on Ubuntu

Once the prerequisites are installed, you can proceed to 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

installing nvm on ubuntu

installing nvm on ubuntu

This command downloads the NVM installation script from the official GitHub repository and pipes it to the bash shell for execution. Make sure to replace v0.39.1 with the latest version available at the time of installation.

After the installation script completes, you may need to close and reopen your terminal window or run source ~/.bashrc to apply the changes to your current shell session.

Step 4: Verify NVM Installation on Ubuntu

To verify that NVM has been successfully installed on your system, you can use the following command:

nvm --version

Verify nvm installation

Verify nvm installation

If NVM has been installed correctly, this command will display the installed version of NVM.

Step 5: Install Node.js Using NVM

Now that NVM is installed, you can use it to install specific versions of Node.js. For example, to install the latest LTS (Long-Term Support) version of Node.js, you can run the following command:

nvm install --lts
installing node.js using nvm in Ubuntu

installing node.js using nvm in Ubuntu

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

Step 6: Switch Between Node.js Versions

One of the key features of NVM is the ability to switch between different Node.js versions with ease. To list all installed Node.js versions on your system, you can use the following command:

nvm ls
listing node.js version in Ubuntu

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.

How to Install NVM on Ubuntu 22.04 – FAQ

What is NVM, and why should I use it?

NVM, or Node Version Manager, is a tool that allows you to manage multiple Node.js installations on your system. With NVM, you can easily switch between different versions of Node.js, install new versions, and manage global and local npm packages. It’s particularly useful for developers who work on projects with specific Node.js version requirements or need to test their applications across different Node.js versions.

How do I install NVM on Ubuntu 22.04?

Installing NVM on Ubuntu 22.04 involves a few simple steps. First, you’ll need to download and run the NVM installation script using curl or wget. Once the script is executed, it will install NVM and configure your system to use it. After installation, you may need to restart your terminal or run a specific command to start using NVM.

Can I install NVM alongside my existing Node.js installation?

Yes, you can install NVM alongside your existing Node.js installation. NVM manages Node.js installations separately from the system’s package manager, allowing you to have multiple Node.js versions installed concurrently. This means you can continue using your current Node.js installation while also using NVM to manage other versions as needed.

How do I use NVM to install a specific version of Node.js?

Using NVM to install a specific version of Node.js is straightforward. Once NVM is installed, you can use the `nvm install` command followed by the desired Node.js version number. For example, to install Node.js version 14.x, you would run `nvm install 14`. After the installation is complete, you can switch to the newly installed version using `nvm use 14`.

Is it possible to uninstall NVM and remove all Node.js versions installed with it?

Yes, you can uninstall NVM and remove all Node.js versions installed with it. To uninstall NVM, you’ll need to run the uninstallation script provided by NVM. Additionally, you can manually delete any Node.js versions installed by NVM from your system. Keep in mind that uninstalling NVM will remove its functionality, so make sure to back up any necessary data or configurations before proceeding with the uninstallation.

Conclusion

Installing NVM on Ubuntu 22.04 allows you to easily manage multiple versions of Node.js on your system, providing flexibility and convenience for 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.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads