How can the default node version be set using NVM?

Matheus Mello
Matheus Mello
September 2, 2023
Cover Image for How can the default node version be set using NVM?

Setting the Default Node Version using NVM: A Step-by-Step Guide

Have you ever found yourself grappling with different Node.js versions when working on different projects? 🤔 Fear not! Today, we'll show you how to easily set the default Node version using NVM (Node Version Manager). 🎉

The Problem: Node Version Juggling

Let's set the scene: you have NVM installed on your Ubuntu with the zsh shell. You have two Node versions available: v6.11.5 and v9.0.0, and the default version set by NVM is v9.0.0. 😬

Every time you need to switch to v6.11.5, it becomes an arduous task. But fret not, as we have the perfect solution for you! 😉

The Solution: Setting the Default Node Version

To set the default Node version to v6.11.5 and make your life easier, follow these simple steps:

Step 1: Open your terminal and type the following command to see the available Node versions:

nvm list

The output should look something like this:

v6.11.5
-> v9.0.0
   system
default -> node (-> v9.0.0)
node -> stable (-> v9.0.0) (default)
stable -> 9.0 (-> v9.0.0) (default)

Step 2: Once you have identified the desired version (v6.11.5), run the following command:

nvm alias default v6.11.5

This command sets v6.11.5 as your default Node version. 🎉

Step 3: To verify that the default version has indeed been changed, run:

nvm list

You should see the updated output:

-> v6.11.5
   v9.0.0
   system
default -> node (-> v6.11.5)
node -> stable (-> v9.0.0) (default)
stable -> 9.0 (-> v9.0.0) (default)

Congratulations! 🎉 You have successfully set v6.11.5 as your default Node version.

Take It a Step Further: Automate Node Version Switching

If you find yourself frequently switching between different Node versions, you can automate this process by including a Node version directive at the top of your project's .nvmrc file. This allows NVM to automatically switch to the specified version when you navigate to your project directory.

To implement this, simply create a .nvmrc file in your project directory and add the desired Node version, like so:

echo "v6.11.5" > .nvmrc

Now, every time you cd into your project directory, NVM will automatically switch to the specified Node version. How cool is that? 😎

Engage with Us!

We hope this guide has cleared up any confusion and made your Node version management journey smoother. If you have any questions or want to share your experience, feel free to leave a comment below or reach out to us on social media. We'd love to hear from you! ✨

Happy coding! 💻🚀

Take Your Tech Career to the Next Level

Our application tracking tool helps you manage your job search effectively. Stay organized, track your progress, and land your dream tech job faster.

Your Product
Product promotion

Share this article

More Articles You Might Like

Latest Articles

Cover Image for How can I echo a newline in a batch file?
batch-filenewlinewindows

How can I echo a newline in a batch file?

Published on March 20, 2060

🔥 💻 🆒 Title: "Getting a Fresh Start: How to Echo a Newline in a Batch File" Introduction: Hey there, tech enthusiasts! Have you ever found yourself in a sticky situation with your batch file output? We've got your back! In this exciting blog post, we

Cover Image for How do I run Redis on Windows?
rediswindows

How do I run Redis on Windows?

Published on March 19, 2060

# Running Redis on Windows: Easy Solutions for Redis Enthusiasts! 🚀 Redis is a powerful and popular in-memory data structure store that offers blazing-fast performance and versatility. However, if you're a Windows user, you might have stumbled upon the c

Cover Image for Best way to strip punctuation from a string
punctuationpythonstring

Best way to strip punctuation from a string

Published on November 1, 2057

# The Art of Stripping Punctuation: Simplifying Your Strings 💥✂️ Are you tired of dealing with pesky punctuation marks that cause chaos in your strings? Have no fear, for we have a solution that will strip those buggers away and leave your texts clean an

Cover Image for Purge or recreate a Ruby on Rails database
rakeruby-on-railsruby-on-rails-3

Purge or recreate a Ruby on Rails database

Published on November 27, 2032

# Purge or Recreate a Ruby on Rails Database: A Simple Guide 🚀 So, you have a Ruby on Rails database that's full of data, and you're now considering deleting everything and starting from scratch. Should you purge the database or recreate it? 🤔 Well, my