Installing Multiple Versions of Node.js Using nvm
Managing Multiple Node.js Versions with NVM
Working on multiple Node.js projects often requires juggling different runtime versions. This article explores how Node Version Manager (NVM) simplifies this process, allowing seamless switching between various Node.js versions without the hassle of manual installations and uninstalls.
Key Advantages of NVM:
- Simplified Version Management: NVM streamlines the process of managing multiple Node.js versions, making it easy to switch between projects with varying version requirements.
- Cross-Platform Compatibility: While primarily designed for Linux and macOS, Windows users can leverage nvm-windows, a functionally equivalent tool.
- Effortless Installation and Usage: NVM offers straightforward installation and commands for installing, listing, and switching Node versions.
Understanding NVM:
NVM (Node Version Manager) is a command-line tool that simplifies the management of multiple Node.js installations. It provides commands to install, switch between, and manage different Node.js versions.
Operating System Support:
NVM directly supports Linux and macOS. For Windows, use nvm-windows (a separate, but similar, project). The core commands outlined below generally work across both NVM and nvm-windows.
Installation:
Windows:
- Uninstall any existing Node.js installations.
- Delete existing Node.js directories (e.g.,
C:Program Filesnodejs
). - Delete the npm installation directory (e.g.,
C:Users<user>AppDataRoamingnpm</user>
). - Download and run the latest stable nvm-windows installer.
macOS/Linux:
Removing prior Node.js and npm installations is optional but recommended. Numerous online resources guide you through this process.
Install NVM using cURL or wget:
cURL:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.35.2/install.sh | bash
wget:
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.35.2/install.sh | bash
(Note: The version number (v0.35.2) might change; check the NVM project page for the latest version.)
After installation, reload or restart your terminal for NVM to take effect.
Using NVM:
Once installed, the nvm
command becomes available in your terminal.
Installing Multiple Node.js Versions:
Use nvm install
followed by the version number:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.35.2/install.sh | bash
This installs Node.js version 12.14.1. NVM uses semantic versioning (SemVer); nvm install 12.14
installs the latest 12.14.x version. nvm ls-remote
(or nvm ls available
for nvm-windows) lists available versions.
Installing npm:
NVM installs a compatible npm version with each Node.js installation. Global npm packages are installed per Node.js version in ~/.nvm/versions/node/<version>/lib/node_modules
, preventing conflicts.
Switching Between Versions:
Use nvm use
followed by the version number:
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.35.2/install.sh | bash
This switches to Node.js 13.6.0. nvm use node
selects the latest version, and nvm use --lts
selects the latest LTS (Long-Term Support) release.
Custom Aliases:
Create custom aliases using nvm alias
:
nvm install 12.14.1
Set a default version with nvm alias default <version></version>
.
Listing Installed Versions:
Use nvm ls
to list installed versions. The currently active version is marked with an arrow. nvm current
shows the active version.
Per-Project Node Version Specification:
Create a .nvmrc
file in a project directory containing the desired Node.js version. NVM automatically detects and uses this version when you cd
into the project directory and run nvm use
. (Optional shell configuration may be needed for automatic activation).
Other NVM Commands:
-
nvm run <version> <command></command></version>
: Runs a command using a specific Node.js version without switching. -
nvm exec <version> <command></command></version>
: Runs a command in a subshell with a specific Node.js version. -
nvm which <version></version>
: Gets the path to the Node.js executable for a specific version.
Conclusion:
NVM is an invaluable tool for Node.js developers, simplifying version management and saving significant time and effort.
FAQs (briefly addressed within the main text):
- Supported OS: Linux, macOS, Windows (nvm-windows).
- Installation: Script execution (details provided).
- Shell Compatibility: Configurable for various shells.
- Other Runtimes: Primarily Node.js, but similar tools exist for other languages.
-
Updating NVM:
nvm update
- Multiple Managers: Avoid using multiple simultaneously.
- Stable/LTS/Dev Versions: All supported.
- npm Management: Managed alongside Node.js versions.
-
Specific Version Installation/Uninstall:
nvm install <version></version>
,nvm uninstall <version></version>
. -
Listing Installed Versions:
nvm ls
-
Setting Default Version:
nvm alias default <version></version>
-
Switching Versions:
nvm use <version></version>
The above is the detailed content of Installing Multiple Versions of Node.js Using nvm. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Article discusses creating, publishing, and maintaining JavaScript libraries, focusing on planning, development, testing, documentation, and promotion strategies.

The article discusses strategies for optimizing JavaScript performance in browsers, focusing on reducing execution time and minimizing impact on page load speed.

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

The article discusses effective JavaScript debugging using browser developer tools, focusing on setting breakpoints, using the console, and analyzing performance.

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

The article explains how to use source maps to debug minified JavaScript by mapping it back to the original code. It discusses enabling source maps, setting breakpoints, and using tools like Chrome DevTools and Webpack.

How to merge array elements with the same ID into one object in JavaScript? When processing data, we often encounter the need to have the same ID...

In-depth discussion of the root causes of the difference in console.log output. This article will analyze the differences in the output results of console.log function in a piece of code and explain the reasons behind it. �...
