How to Install NVM for Node.js on Ubuntu
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.
Prerequisites:
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).
Step 1: Update Your System
First, make sure your system is up-to-date by running the following command:
sudo apt update && sudo apt upgrade -yStep 2: Install Dependencies
Before installing NVM, ensure that your system has
curlinstalled, as it is required to fetch the installation script.
sudo apt install curl -yStep 3: Install NVM Using cURL
Now, you can install NVM by running the installation script. Execute the following command to download and install NVM from its official repository:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bashThis 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
~/.zshrcfile, depending on your shell.
Install the latest stable version of NVM.
Step 4: Reload the Shell
Once the installation is complete, you’ll need to reload your shell configuration for the changes to take effect. Run the following command:
source ~/.bashrcIf you’re using a different shell (e.g., Zsh), you can run:
source ~/.zshrcAlternatively, you can close and reopen the terminal.
Step 5: Verify NVM Installation
To confirm that NVM was successfully installed, run:
nvm --versionThis should display the installed version of NVM, indicating that the tool is now available for use.
Step 6: Install Node.js Using NVM
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:
nvm install nodeThis command installs the latest stable release of Node.js. To install a specific version, replace
nodewith the desired version number:
nvm install 14.17.0Step 7: Switch Between Node.js Versions
NVM allows you to switch between different versions of Node.js easily. To see which versions are installed on your system, run:
nvm lsTo switch to a specific version, use:
nvm use 14.17.0If you want to set a default version of Node.js for your system, use:
nvm alias default 14.17.0Step 8: Uninstall Node.js Versions
If you ever need to uninstall a Node.js version, you can use:
nvm uninstall 14.17.0Conclusion
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!


