Install and Manage Multiple Versions of Node.js by NVM✅

Photo by Clark Tibbs on Unsplash

Install and Manage Multiple Versions of Node.js by NVM✅

Sometimes, when you want to work on different version of Node.js, you've to install it and it becomes headache to uninstall the current Node.js and install the different one. This is where NVM comes in the picture. NVM makes it easier to install multiple version of Node.js.

NVM allows you to install different versions of Node, and switch between these versions depending on the project that you're working on via the command line.

🍁Install NVM on Windows

To install NVM on windows, there's a tool created by coreybutler to provide an nvm experience in Windows called nvm-windows.

Download the nvm-setup.zip from the assets table located over here. Unzip/Extract the contents (The Zip file should be present in the Downloads folder or the destination you choose to download) by extracting it to nvm-setup.

Complete the installation wizard and when you are done, just check that nvm has been installed by running:

nvm version

If nvm was installed correctly, this command will show you the nvm version installed.

🍁Install nvm on Ubuntu and Mac OS

🍀1. Run the nvm installer

Open the terminal and paste the command

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

# or

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

You can use curl or bash depending on the command available on your device.

These commands will clone the nvm repository to a ~/.nvm directory on your device.

🍀2. Update your profile configuration

The installation process from step 1 should also automatically add the nvm configuration to your profile. If you're using zsh, that would be ~/.zshrc. If you're using bash, that would be ~/.bash_profile...or some other profile.

If it doesn't automatically add nvm configuration, you can add it yourself to your profile file:

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 command above loads nvm for use.

🍀3. Reload the shell configuration

With your profile configuration updated, now you will reload the configuration for your terminal to use:

source ~/.bashrc

With this command executed, nvm is ready for you to use. You can confirm that nvm is installed correctly by running:

nvm -v

🍁Install and Configure Node.js

With nvm installed, you can now install, uninstall, and switch between different Node versions in your Windows, Linux, or Mac device.

  • You can install Node versions like this:

nvm install latest

This command will install the last version of Node.

  • You can install specific version of Node like this:

nvm install vX.Y.Z

This will install the X.Y.Z Node version.

  • You can also make a version your default by running:

nvm alias default vX.Y.Z

  • If you want to use a specific version at any point, you can run the following in your terminal:

nvm use vA.B.C

That's all, NVM makes it easier to manage multiple versions of Node.js across different projects that require different versions.

Thanks for reading my blog. If you like it don't forget to subscribe it and comment down if you have any queries.

Did you find this article valuable?

Support Sagar Medtiya by becoming a sponsor. Any amount is appreciated!