Node Version Manager (NVM) is a popular tool for managing multiple versions of Node.js on a single machine. It simplifies the process of installing, updating, and switching between different Node.js versions, making it an essential tool for Node.js developers. If you’re using Ubuntu, the installation of NVM is quick and easy. This guide will walk you through the steps to install NVM on your Ubuntu system.
A fresh Ubuntu system (Ubuntu 20.04/22.04 or newer).
Access to the terminal with user privileges (either root or a user with sudo access).
First, make sure your system is up-to-date by running the following command:
Before installing NVM, ensure that your system has curl
installed, as it is required to fetch the installation script.
Now, you can install NVM by running the installation script. Execute the following command to download and install NVM from its official repository:
This command downloads the installation script and pipes it to bash
, which will install NVM on your system. The script will automatically:
Add the necessary environment variables to your ~/.bashrc
, ~/.bash_profile
, or ~/.zshrc
file, depending on your shell.
Install the latest stable version of NVM.
Once the installation is complete, you’ll need to reload your shell configuration for the changes to take effect. Run the following command:
If you’re using a different shell (e.g., Zsh), you can run:
Alternatively, you can close and reopen the terminal.
To confirm that NVM was successfully installed, run:
This should display the installed version of NVM, indicating that the tool is now available for use.
Now that NVM is installed, you can easily install any version of Node.js. For example, to install the latest stable version of Node.js, use:
This command installs the latest stable release of Node.js. To install a specific version, replace node
with the desired version number:
NVM allows you to switch between different versions of Node.js easily. To see which versions are installed on your system, run:
To switch to a specific version, use:
If you want to set a default version of Node.js for your system, use:
If you ever need to uninstall a Node.js version, you can use:
Installing NVM on Ubuntu allows you to easily manage multiple Node.js versions, which is particularly useful for development environments where different projects may require different versions. The process is simple, and with NVM, you can quickly install, switch, and remove versions of Node.js as needed.
Let me know if you encounter any issues or need further help!