DEV Community

Sandip Shrestha
Sandip Shrestha

Posted on

1

Struggling with Manual Node Switching? NVM Has Your Back

Node Version Manager (NVM)

You’re ready to start a new project, but the Node.js version you need isn’t the one you have installed. Or worse, you’re juggling multiple projects, each requiring a different Node.js version. You sigh, open Google, and start searching for uninstall and reinstall commands—again. Frustrating, right?

What if I told you there’s a tool that makes all of this hassle disappear? Meet Node Version Manager (NVM)—your ultimate solution for managing multiple Node.js versions effortlessly. Say goodbye to manual switching and hello to smooth, stress-free Node.js management.

Why you need NVM

Let’s dive into a real-world scenario: You’re working on multiple projects. One project requires an older Node.js version, while another uses the latest tools and frameworks that demand the newest version. You can’t use the same Node.js version for both, so what do you do?

Manually switching versions becomes a nightmare. First, you uninstall the current Node.js version on your device. Then, you search Google for the required version, install it, and start working. Once you switch to the other project, you repeat the whole process—uninstall, reinstall, and hope nothing breaks. It’s a lot of hassle, isn’t it?

That’s where NVM comes to the rescue. Whether you discovered it here or a friend told you about it, NVM will transform your workflow. With NVM installed, you can effortlessly manage multiple Node.js versions on your device. Install as many versions as you need, list them, and switch between them with a single command. However, keep in mind—NVM doesn’t let you use two different versions in separate terminals simultaneously. That’s not how it’s meant to work.

Let's get started with installation.

Installing NVM on macOS or Linux:

Open your terminal and run the following command:

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

Restart your terminal or run:

source ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

If you're using Zsh, run:

source ~/.zshrc
Enter fullscreen mode Exit fullscreen mode

Verify installation by running:

nvm --version
Enter fullscreen mode Exit fullscreen mode

Installing NVM on Windows:

Download the nvm-setup.exe from https://github.com/coreybutler/nvm-windows/releases and run the installer.

After installation, restart your terminal and run:

nvm --version
Enter fullscreen mode Exit fullscreen mode

If installed correctly, you’ll see the version number of NVM.

Key Features of NVM:

Install Specific Node.js Version:

nvm install 22.12.0
Enter fullscreen mode Exit fullscreen mode

Switching Between Versions:

nvm use 22.12.0
Enter fullscreen mode Exit fullscreen mode

Listing Installed Versions:

nvm ls
Enter fullscreen mode Exit fullscreen mode

Setting Default Version:

nvm alias default 22.12.0
Enter fullscreen mode Exit fullscreen mode

Project-Specific Node.js Versions:

In your project’s root directory, create a .nvmrc file with the desired version:

echo "14.17.0" > .nvmrc
Enter fullscreen mode Exit fullscreen mode

Whenever you navigate to your project directory, simply run:

nvm use
Enter fullscreen mode Exit fullscreen mode

NVM will automatically switch to the version specified in .nvmrc.

Sad news for Windows users (including me): NVM on Windows differs slightly from the original NVM and doesn't support .nvmrc. But don’t worry, you can still manually switch versions using nvm use!

Conclusion

Managing multiple Node.js versions doesn’t have to be a tedious process. With NVM, you have a powerful and hassle-free solution to streamline your workflow and focus on what truly matters—building amazing projects. Whether you're a seasoned developer or just starting out, NVM saves you time and effort by simplifying version management.

So, why go through the frustration of uninstalling and reinstalling Node.js every time? Embrace NVM, and make seamless Node.js management a reality. Install it today, and take your productivity to the next level!

What are you waiting for? Try NVM today and unlock hassle-free Node.js management!
Happy coding! 🎉

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

Top comments (0)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.