Set default node version with NVM

I was recently figuring out how to use nvm, and one thing that stood out to me is that I needed to set the default version of node that I wanted to use when opening a new tab.

Because I was new to using nvm it took me a while to find the commands. So, if you happen to find this article while configuring nvm, hopefully you find this useful.

# Install the version that you would like 
nvm install 12.20.1

# Set 12.20.1 (or another version) as default
nvm alias default 12.20.1

Then you can open a new tab and if you run node -v, you should see v6.1.0 (or whichever version you set as the default.

Easy peasy, right? Hopefully this helps you if you’re having some issues!

48 thoughts on “Set default node version with NVM”

  1. Thanks for sharing, I was having this same problem with nvm, and I didn’t even realize it! Does that make sense :p

    1. Makes sense to me 😄 I could totally see how someone would think that they just had to use nvm use 6.1.0 each time they opened a tab, because that’s what I did for a little bit. 😜

  2. I have this weird issue with nvm and Yarn:
    I have defaulted nvm to node version 8.4.0. Now, when I do yarn –version, I get an old version (0.27.5).
    However, when I do nvm use 8.4.0 (which should not be necessary), THEN I get the new version of Yarn (1.0.2). Is there an explanation for this strange behaviour?

    1. Off of the top of my head, I’m not too sure. The only thing I can think of is that the defaulting is not working properly and that you’re getting different global versions of Yarn?

  3. thats what i was looking for; thx

    in retrospect,
    nvm | grep default

    shows the options on the command line (mac / linux) , but your blog got me there first

  4. The first time you do an “nvm install”, it sets “nvm alias default” (in ~/.nvm/alias) to the version you install. will then give you that version in every new shell, even if you nvm install a different version. In order to let nvm install set a new default, you can clear the existing one with
    nvm alias default ”

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.