JavaScript Development Space

How to Change Node Version with NVM

Node Version Manager (NVM) is a powerful tool for managing multiple versions of Node.js on the same machine. With NVM, you can easily switch between different Node versions, making it ideal for projects that require specific versions. Here’s a step-by-step guide on how to change Node.js versions using NVM.

1. Check Installed Node Versions

To see which versions of Node.js are installed on your machine via NVM, use the following command:

nvm list

This will display a list of all the Node.js versions you have installed, including the default version (if any) and the one currently in use.

2. Install a New Node Version

If you want to switch to a version that isn’t installed yet, first, you need to install it. You can install any available Node.js version using the following command:

nvm install "version"

For example, to install Node.js version 18.20.4

nvm install 18.20.4

NVM will download and install the specified version.

3. Switch to a Different Node Version

To change to a specific Node.js version that is already installed, use:

nvm use "version"

For example, to switch to Node.js version 20.17.0:

nvm use 20.17.0

The terminal will now use the selected Node.js version for the current session.

4. Set a Default Node Version

If you want a specific version to be the default every time you open a new terminal session, use the following command:

nvm alias default "version"

For example, to set Node.js version 18.20.4 as the default:

nvm alias default 18.20.4

This will ensure that this version is used whenever you open a new terminal window unless you explicitly switch to another version.

5. Check the Current Node Version

To verify which Node.js version is currently in use, simply run:

node -v

This will display the active Node.js version being used in the current session.

6. Uninstall a Node Version

If you no longer need a particular Node.js version, you can uninstall it with the following command:

nvm uninstall "version"

For example, to uninstall version 12.22.1:

nvm uninstall 12.22.1

Conclusion

NVM makes managing and switching between multiple versions of Node.js easy and efficient. Whether you're juggling different projects that require specific Node versions or testing your code across versions, NVM provides a simple solution to handle it all.

JavaScript Development Space

© 2024 JavaScript Development Space - Master JS and NodeJS. All rights reserved.