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!

Responses

  1. Rocco Tripaldi Avatar
    Rocco Tripaldi

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

    1. Eric Binnion Avatar

      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. blowery Avatar

    https://github.com/wbyoung/avn is pretty handy too. It looks for a special dotfile and automatically switches the node version.

    1. Eric Binnion Avatar

      And here I was trying to be helpful to others, and I learned something. ?

    2. blowery Avatar

      There’s also this monster issue on the nvm repo: https://github.com/creationix/nvm/issues/110

  3. JOANDER VIEIRA CANDIDO Avatar
    JOANDER VIEIRA CANDIDO

    Obrigado !

  4. Josh Betz Avatar

    I find nvm to be pretty slow, so I install the latest version with homebrew and just use nvm if I want to temporarily switch to a different version. If you load it with –no-use, it’s much faster, but you have to manually activate whatever version you want.

    https://github.com/joshbetz/dotfiles/blob/407c2828839ac12bfdd17c5f84c2d6bc0df0e944/shell/env#L7-L9

  5. Brad Parks Avatar

    you can also do “nvm alias default node” and it will do it for the latest version of node you have

    1. Eric Binnion Avatar
  6. Mac Liems Avatar

    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. Eric Binnion Avatar

      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?

  7. DV Avatar

    ohh! thank you very much for tha tuto!

  8. Mario Avatar

    Muchas gracias!!!

  9. Vinícius

    Nice tweak man, thanks for sharing!

  10. fred Avatar

    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

  11. Adam Becker Avatar
    Adam Becker

    Thanks! Very helpful.

  12. kevin s Avatar

    Thanks. If the nvm documentation was made of paper, I’d burn it. geezus

    1. Eric Binnion Avatar

      You’re welcome! 🙂

  13. David Avatar

    Does it work with windows? How would it be for windows?

  14. Manmohan Avatar

    Thank you, it’s very helpful 🙂

  15. Rob Dyson Avatar
    Rob Dyson

    Thanks for this!

  16. Jasmine Martin Avatar
    Jasmine Martin

    Thank you for making that quick and to the point! Bless

  17. Dan Hauk Avatar

    Thanks! It was always a pain forgetting to change versions and getting errors when running npm start. This is exactly what I was looking for.

  18. Sonic Avatar

    Thanks a lot! ?

  19. Denis Howe Avatar

    The first time you do an “nvm install”, it sets “nvm alias default” (in ~/.nvm/alias) to the version you install. nvm.sh 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 ”
    HtH

  20. John Avatar

    Thanks for sharing, mate!

  21. Ben Avatar

    Thanks. This will save me some time each time my machine restarts!

  22. Robin Avatar

    Thanks!

  23. Jonathan Quimbly Avatar
    Jonathan Quimbly

    Thanks kindly. https://nvm.sh/ doesn’t let as clearly how to do this.

  24. Luke Chinworth Avatar
    Luke Chinworth

    Thanks!

  25. Ishika Avatar
    Ishika

    Thanks much!

  26. Ayoub Avatar

    Thank you

  27. volodymyr Avatar
    volodymyr

    Thank you very match

  28. Maxwell Souza de Carvalho Avatar
    Maxwell Souza de Carvalho

    Very straightfoward, thank you

  29. Chad Avatar

    Thank you!

  30. Tim Avatar

    Thanks! Solved my problem ?

  31. Nate Avatar

    Very useful, thank you!

  32. Osk Avatar

    Thanks again. Once yearly I fall here.

    1. Eric Binnion Avatar

      hehe. You’re always welcome back ?

  33. Mark George Avatar
    Mark George

    Thanks Eric. You know this is the top hit on the Googs for setting default node version with nvm?

      1. Sten Avatar

        Yup, I was just searching for this and found you! ? Thanks!

  34. Frank Avatar

    This is like the third time your post save my day.

  35. nunyvega Avatar

    Thanks! you’ll save me multiple `nvm use 16.7.0`

Leave a Reply to Josh BetzCancel reply

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

Discover more from Eric Binnion

Subscribe now to keep reading and get access to the full archive.

Continue reading