Short answer: on macOS and Linux, install NVM with the official script from the nvm repository (curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash) or, on a Mac, with Homebrew (an option the nvm project does not officially support). On Windows, use the separate nvm-windows installer. Then run nvm install --lts (nvm install lts with nvm-windows) to get Node.js. Each operating system has its own step-by-step guide below.
Node Version Manager (NVM) is an essential tool for any JavaScript developer. It allows you to manage multiple javascript projects and environments of Node.js and switch between them depending on the project needs. This flexibility helps developers manage dependencies, test new features, and ensure compatibility across different Node versions without disrupting the entire development environment.
In this quick guide, we'll cover how to install NVM on windows, mac or linux computers. But, if you encounter any issues we do have more detailed instructions for each separate operating system:
Since NVM runs on the command line, we will assume you have some fair knowledge about what is and how to use the command line.
Steps for installing NVM on Windows
-
Download the Installer from the nvm-windows GitHub repository and download the latest release.
-
Run the Installer: Launch the downloaded installer. Follow the prompts to install NVM for Windows. Default settings are recommended for most users.
-
Verify Installation: Open your command prompt and type
nvm --version. If NVM is installed correctly, the version number will be displayed.
🚨 IMPORTANT! Ensure that the NVM directory is added to your system's PATH. The installer usually handles this step.
Here is a more detailed explanation on how to install NVM on windows.
Steps for installing NVM on macOS and Linux
The easiest and recommended is using the curl or wget command:
-
Open Your Terminal: Access your terminal through your macOS or Linux system.
-
Install Script: Run the following command in the terminal:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bashOr, if you prefer using wget:
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash- Update Your Profile: Add the following to your shell profile file (.bash_profile, .zshrc, .profile, etc.):
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm-
Restart Your Terminal: To ensure the changes take effect, restart your terminal.
-
Verify Installation: In the terminal, type
nvm --version. A successful installation will show the version number of NVM.
Why Use NVM?
- Multiple Node.js Versions: Easily switch between Node versions per project.
- Global Packages per Version: Install global NPM packages specific to each Node version without conflicts.
- Development Flexibility: Easily test applications across different Node versions.
Conclusion
With NVM installed, you can now install any version of Node.js by simply running nvm install node_version. For instance, nvm install 14.17.0 will install Node.js version 14.17.0. You can switch between installed versions using nvm use node_version.
Troubleshooting
If you encounter any issues during the installation, make sure that:
- Your internet connection is stable.
- You have proper write permissions in your system.
- You've closed and reopened your terminal window to refresh the environment variables.
For more detailed documentation, visit the NVM GitHub Page.
With NVM handling your Node.js versions on any operating system, you are ready to build real applications. A programming bootcamp gives you a structured path to do that, with hands-on projects and mentor feedback.
Frequently asked questions
Is nvm-windows the same tool as nvm for macOS and Linux?
No. nvm-windows is an independent project with its own installer and code, while nvm for macOS and Linux is a shell script loaded from your profile. Many everyday commands look alike, such as nvm install, nvm use and nvm list, but options and behavior differ, so follow the documentation of the project that matches your operating system.
Should I uninstall Node.js before installing NVM?
On Windows, yes: nvm-windows expects you to remove any existing Node.js installation and its leftover folders first, otherwise the two can conflict. On macOS and Linux a system Node.js can coexist, because the version NVM activates takes priority in the PATH, but removing it avoids confusion about which node binary and global packages are actually running.
How do I install the latest LTS version of Node.js with NVM?
On macOS and Linux, run nvm install --lts and then nvm use --lts to activate it. With nvm-windows, run nvm install lts, then nvm use followed by the version number it reports. LTS releases receive long-term maintenance and security fixes, which makes them the safer choice for most projects compared with the newest current release.
How can a project switch to its Node.js version automatically?
Add a .nvmrc file to the project root containing the required version, for example 14.17.0. Inside that folder, nvm use reads the file and switches to that version, and nvm install downloads it if it is missing. This works with nvm on macOS and Linux; for fully automatic switching, add a shell hook that runs nvm use whenever you change directories.
