NVM, the Node.js version manager

By Jose Daniel on May 13, 2021

What is NVM?

NVM allows developers to switch between different versions of Node. This is particularly useful when an application needs to run a specific version of Node.js but the system is using a different one, here is when NVM shines.

NVM installation.

To install or update NVM, you should run the install script. To do that, you need to download the script and run it.

# Using cURL
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash

# Or using Wget
# wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash

These commands will downloads a script and runs it. Then we have load nvm.

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

In order to verify the installation, run:

command -v nvm

It should output nvm if the installation was successful

How to use NVM?

First you need to download Node.js. This will download the latest version of Node.js

nvm install node 

You can also install a specific version of Node.js

nvm install 6.14.4 # or 10.10.0, 8.9.1, etc

List of all available versions

nvm ls-remote

List of the Node.js versions you have installed

nvm ls

Use a specific version of Node.js

nvm use 8.9.1

Conclusion

Is incredibly easy to switch between multiple Node.js versions using NVM. If you are in a situation where the project requires a different version of Node.js or you just want to test your project with another version, Node Version Manager can help you save a lot of time.