How to Install and Manage Node.js Versions with NVM

Node Version Manager (NVM) allows you to manage multiple installations of Node.js and npm. It's essential for projects requiring different Node.js versions.

Installing NVM on Linux

To install NVM on macOS and Linux, use the curl command:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

Installing NVM on Windows

On Windows, the installation of NVM—Node Version Manager—requires a different approach than on UNIX-based systems. Instead of the traditional NVM, Windows users should opt for nvm-windows, a modified version designed specifically for Windows environments.

To get started, download nvm-windows from its official GitHub repository:

https://github.com/coreybutler/nvm-windows/releases

Follow the provided installation instructions to set up NVM on your Windows machine. This typically involves running an installer which configures NVM and updates your system environment variables automatically.

Installing and Managing Node.js with NVM

With NVM installed, managing Node.js versions becomes straightforward. To install a new version of Node.js, use the install command:

nvm install 20.11.1

Switch to your newly installed version with:

nvm use 20.11.1

Check your active version of Node.js by running:

node -v

Switching Between Different Node.js Versions

NVM allows you to switch between any versions of Node.js that you have installed. This feature is particularly useful for developers working on multiple projects requiring different versions.

nvm use 18.19.1

Confirm the switch by checking the version again:

node -v

Additional Resources

For detailed instructions on installing Node.js and npm directly, without NVM, you can visit our pages on How to Install Node.js and How to Install npm.

With NVM, you can easily manage multiple Node.js environments on your machine, simplifying development processes and ensuring compatibility across different projects.