This short tutorial will explain how to install node version manager (nvm) on Windows or Linux and Mac OS systems. Node Version Manager is very useful when working with node.js based projects
Contents
What is Node Version Manager?
nvm
stands for Node Version Manager. It’s a tool used to manage multiple Node.js versions. nvm
allows you to easily install, switch between, and manage many different versions of Node.js on a single system. This is especially useful for developers who need to test their applications across multiple Node.js versions or work on different projects that each require a specific Node.js version.
Why developers like nvm
nvm
is favored in development environments where maintaining consistent Node.js versions across different projects or team members is important. It simplifies the process of managing Node.js versions and reduces potential conflicts between project dependencies and the Node.js runtime.
- Multiple Node.js Versions: Install and maintain multiple versions of Node.js and npm (Node.js package manager) without needing to manually download and configure them.
- Easy Switching: Switch between installed Node.js versions with a simple command. This helps in testing applications across different Node.js environments.
- Project-Specific Versions: You can specify a Node.js version for a specific project.
nvm
will automatically use the right version when you’re working on that project. - No Need for Sudo:
nvm
installs Node.js in your user space, eliminating the need forsudo
commands (on Unix-based systems) and avoiding permission issues often encountered with global installations. - Compatibility:
nvm
works on various Unix-like operating systems, including macOS and Linux. For Windows, a separate version callednvm-windows
is available with similar functionality. - Version Management: Easily install and uninstall different Node.js versions as needed.
- Automatic Version Switching: By placing a
.nvmrc
file in your project’s root directory with the desired Node.js version,nvm
can automatically switch to this version when you navigate to the directory.
Installing nvm on Windows
To install NVM (Node Version Manager) on Windows, you’ll need to use a version of NVM that’s specifically designed for Windows, known as “nvm-windows”. Here’s a step-by-step guide to install it:
Download nvm for windows
There are several options for downloading nvm
for windows. I recommend downloading the .exe
file.To download nvm
for Windows:
- Go to the nvm-windows releases page on GitHub.
- Download the latest version. It’s typically provided as a
.zip
file or an installer (.exe
file). The installer version (nvm-setup.zip
) is generally easier to use.
Install nvm
If you downloaded the installer (.exe
file), simply run it and follow the on-screen instructions.
During the installation, the installer may prompt you to specify the paths for Node.js and npm. It will create these directories for you. We recommend using the default paths unless you need to change them for a specific reason. Proceed to complete the installation process.
Verify the Installation on Windows
Open a new command prompt or PowerShell window then run the following command to check if nvm
has been installed successfully:
nvm version
Important notes
- Administrator Rights: You may need administrator rights to install
nvm
on Windows, especially if you are installing it in a system directory. - Environment Variables:
nvm
should automatically set up the necessary environment variables. If you encounter any issues, you may need to manually check these settings. - Existing Node.js Installation: If you have an existing Node.js installation, you may want to uninstall it before installing Node.js through
nvm
to avoid any conflicts. - System Restart: After installation, you might need to restart your system or at least restart your command line tool to ensure the environment variables are properly set.
By following these steps, you should be able to successfully install nvm
on your Windows system, allowing you to manage multiple Node.js versions easily.
How to install nvm on Linux or Mac OS
To install nvm
on Ubuntu Linux or Mac OS, you can follow these steps:
Open your Terminal and download nvm
You can do this by searching for “Terminal” in your system’s application launcher or by pressing Ctrl + Alt + T
on Linux. For Mac OS find Terminal in the Applications > Utilities folder, or you can use Spotlight (Cmd + Space
) to search for it.
Use the curl or wget command to download and run the installation script. It’s important to check the latest version of NVM from the official GitHub repository for the most recent install command.
You can use the following commands: Using curl
:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Or using wget
:
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Update your System’s Environment
The script updates your bash profile to load nvm
. You need to either close and reopen your terminal or source your profile file to reflect these changes. You can source your profile with the following command:
source ~/.bashrc
If you’re using a different shell like Zsh, the file might be ~/.zshrc
or another profile file.
Verify the Installation
After installation, verify that nvm
has been installed successfully by checking its version:
nvm --version
How to use nvm to install and switch between Node versions
In this section, we look at what you can do with nvm
. To use nvm
open up a command prompt, terminal, or PowerShell shell.
Install Node.js
Now, you can install Node.js using nvm
. For instance, to install the latest version of Node.js, you can use:
nvm install node
You can also install several specific versions of Node.js depending on your needs. To install a specific version specify the version number like this:
nvm install 20.10.0
Switch Between Node Versions
There are times when you need to switch to a newer or older version of Node.js. For example, when you have an old project that is incompatible with the latest version of Node.js and you want to work on it. You can switch between installed Node.js versions with the command: nvm use
followed by the version number. For example:
nvm use 20.10.0
List Installed Node Versions
To see all the Node.js versions installed on your system through NVM, use:
nvm ls
Conclusion
In conclusion, we now know how to install node version manager and can use it to manage our node versions. This is helpful when working with JavaScript-based packages and frameworks.
To stay up to date on programming and software development-related articles follow me on X:
Follow @tmdev82