Want to go back?

Manage Multiple Node.js Versions with NVM

Published on
2 mins read
––– views

Why NVM (Node Version Manager)?

As a JavaScript developer, one effective strategy for managing multiple Node.js versions is to adopt NVM. This tool allows you to easily switch between environments, ensuring consistency across your projects.

Let me guide you through the setup and usage:

Step 1: Install NVM

Run the following command to install NVM:

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

Step 2: Verify Installation

After installation, verify by checking the version:

nvm --version

Step 3: List Available Node.js Versions

To see all available Node.js versions you can install, run:

nvm ls-remote

Step 4: Install a Node.js Version

For my purposes, I need to install the latest stable version of Node.js, and as of this writing, I will install version v20.17.0 using the following command:

nvm install v20.17.0

Step 5: List Installed Node.js Versions

To see all the Node.js versions you have installed, run:

nvm ls

On my PC, the installed versions are as follows:

[joseph☮mathagu-pc]-(~)
└> nvm ls
       v10.23.0
        v14.9.0
       v14.19.2
       v16.14.2
       v16.20.2
        v17.8.0
       v18.15.0
       v20.11.1
->     v20.17.0
default -> node (-> v20.17.0)

Step 6: Use a Node.js Version

Switch to the desired Node.js version:

nvm use v20.17.0

Step 7: Set a Default Version

To set a default Node.js version for new shells:

nvm alias default v20.17.0

Conclusion

NVM simplifies managing multiple Node.js versions, allowing you to easily switch, install, and set defaults as needed.

Thank you for reading!