Simplifying Node.js Version Management with NVM

Photo by Kit Suman on Unsplash

Simplifying Node.js Version Management with NVM

How to install and run multiple versions of Node.js on your machine

When I first started working with Node.js, I would directly install it from the official Node.js website using their recommended installer. It was a straightforward process: click, download, run the installer, and voilà! I had the latest version of Node.js and npm installed on my machine, ready to kick off my new project.

However, Node.js evolves at lightning speed. It feels like there’s a new upgrade almost every other month, and by the time I was ready to start a new project, I’d have to update to the latest Node.js version to access the newest features.

But here’s the catch: when I revisited my old projects, I’d be greeted by a barrage of red error messages. Suddenly, my previously smooth-running project was plagued with npm packaging incompatibilities and other issues. It was frustrating to say the least.

Enter Node Version Manager (NVM). This nifty tool allows you to manage multiple Node.js versions on your machine, making it easy to switch back and forth based on your project requirements. Let’s dive into how you can harness the power of NVM:

Installing NVM

Windows Users

If you’re on Windows, fear not! While NVM is primarily supported on Linux and Mac, there’s a similar tool called nvm-windows that provides an NVM-like experience for Windows users. Here’s what you need to do:

  1. Visit the NVM for Windows GitHub repository.

  2. Download the latest version of the installer from the releases page.

  3. Run the installer and follow the on-screen instructions.

Linux and Mac Users

For Linux and Mac users, open your terminal and execute the following command to install NVM:

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

This command will clone the NVM repository to ~/.nvm on your device.

Using NVM

Now that NVM is installed, let’s explore its capabilities:

  1. Installing Node.js Versions:

    • To install the latest version of Node.js, use:

        nvm install latest
      
    • To install a specific version (e.g., 14.17.0), run:

        nvm install 14.17.0
      
  2. Setting a Default Version:

    • Set a default Node.js version with:

        nvm alias default 14.17.0
      
  3. Switching Between Versions:

    • Use the following command to switch to a specific version:

        nvm use 14.17.0
      

Remember to uninstall any existing Node.js installations to avoid conflicts with NVM. Now you’re equipped to manage your Node.js versions effectively!

Happy coding! 🚀


Feel free to share this blog post with fellow developers who want to streamline their Node.js development workflow. If you have any questions or need further assistance, drop a comment below! 😊