Home > Software > How to Install NVM (Node Version Manager) on Ubuntu

How to Install NVM (Node Version Manager) on Ubuntu

Anastasios Antoniadis

Share on X (Twitter) Share on Facebook Share on Pinterest Share on LinkedInNode Version Manager (NVM) is an essential tool for managing multiple Node.js versions on a single machine. It provides the flexibility to switch between Node.js versions seamlessly, catering to the diverse requirements of different projects. This capability is particularly beneficial for developers working …

Node JS

Node Version Manager (NVM) is an essential tool for managing multiple Node.js versions on a single machine. It provides the flexibility to switch between Node.js versions seamlessly, catering to the diverse requirements of different projects. This capability is particularly beneficial for developers working on multiple Node.js applications or those who need to test their applications across various Node.js versions. This article provides a detailed guide on installing NVM on an Ubuntu system, enabling you to take full advantage of this powerful tool.

Prerequisites

Before proceeding with the installation of NVM on Ubuntu, ensure you have:

  • A running Ubuntu system (The steps covered are also applicable to other Debian-based distributions).
  • Access to a terminal.
  • Basic familiarity with terminal commands.

Step 1: Downloading the NVM Installation Script

NVM installation on Ubuntu is initiated through a shell script. Open your terminal, and use curl or wget to download and run the NVM installation script from the NVM GitHub repository. If you don’t have curl or wget installed, you can install them using sudo apt install curl or sudo apt install wget.

Using curl:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

Using wget:

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

Note: Make sure to check the official NVM GitHub page for the latest version of NVM and update the command accordingly.

Step 2: Updating Your Profile

Once the script executes, it attempts to add the necessary NVM export commands to your shell profile files (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc). To ensure the changes take effect, you might need to reload your profile. You can do this by closing and reopening your terminal or by sourcing your profile file.

For bash, you might use:

source ~/.bashrc

For zsh, you might use:

source ~/.zshrc

Step 3: Verifying the Installation

After installation, verify that NVM is correctly installed and accessible by executing:

nvm --version

If the installation was successful, you should see the version of NVM displayed in the terminal.

Step 4: Installing Node.js Using NVM

With NVM installed, you can now install any version of Node.js. For example, to install the latest version of Node.js, you can use:

nvm install node

To install a specific version of Node.js, specify the version number:

nvm install 14.17.0

You can list all installed Node.js versions and see which one you’re using with:

nvm ls

And you can switch between installed Node.js versions using:

nvm use 14.17.0

Troubleshooting

  • Command ‘nvm’ not found: If you encounter this issue after installation, it’s likely that the NVM export lines were not correctly added to your shell profile file. You can manually add them (as found in the installation script output) to your .bashrc, .zshrc, or equivalent file.
  • Permission Issues: Running the installation script without superuser privileges should avoid permission issues. If you encounter permission-related errors, ensure you’re not using sudo for NVM commands.

Conclusion

NVM is a powerful tool that simplifies the management of Node.js versions on a single machine, making it an indispensable utility for Node.js developers. By following the steps outlined in this guide, you can install NVM on your Ubuntu system and leverage its capabilities to manage Node.js versions effectively, thus ensuring compatibility and efficiency across your development projects.

Anastasios Antoniadis
Follow me
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x