How to Install and Use NVM (Node Version Manager) on Ubuntu 22.04

Estimated reading: 3 minutes 653 views

NVM, also called “Node Version Manager” is used for installing and managing multiple Node.js versions in Linux. It provides a command line utility that helps developers install multiple Node versions and switch between multiple versions as per their project requirements. NVM is beneficial if you work on multiple projects requiring different Node versions.

In this post, we will show you how to install and use NVM to manage Node.js on Ubuntu 22.04.

Install NVM

By default, NVM is not included in the Ubuntu default repository. So you will need to install it from the script.

Run the following apt command to update:

apt update

Install the CURL and Gnupg2 with the following command:

apt-get install curl gnupg2 -y

Next, run the following command to download and run the NVM installation script:

curl https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash

Now, activate all settings using the following command:

source ~/.bashrc

Now, verify the NVM version using the following command:

nvm --version

Install Node.js with NVM

NVM is now installed in your system. You can now use the NVM command line to install any Node.js version to your system.

For example, to install the latest version of Node.js, run the following command:

nvm install node

You should see the following output:

To verify the installed version of Node.js, run the following command:

node --version

You should see the following output:

If you want to install the latest stable version of Node.js, run the following command:

nvm install node --lts

You should see the following output:

To install the specific Node.js version (12.17.0), run the following command:

nvm install 12.17.0

Now, verify the current Node.js version using the following command:

node --version

You should see the following output:

Use NVM to Manage Node.js Versions

To list all installed Node.js versions in your system, run the following command:

nvm ls

You should see the following output:

You can find all available Node.js versions using the following command:

nvm ls-remote

To set your default Node.js version to 12.17.0, run the following command:

nvm use 12.17.0

To find the default version for the current user, run the following command:

nvm run default --version

To remove a specific Node.js version from your system, run the following command:

nvm uninstall v21.6.2

Conclusion

In this guide, we explained how to install and use NVM on Ubuntu 22.04. You can now use the NVM to manage multiple Node.js versions and switch between them. We hope you can now run your application with any Node.js version.


Share this Doc

How to Install and Use NVM (Node Version Manager) on Ubuntu 22.04

Or copy link

CONTENTS