Upgrade Node.js via NPM

Written by David Walsh on March 7, 2013 · 31 Comments

I was recently installing a utility via NPM when I learned that my version of Node.js itself was out of date.  No worries -- simply upgrade my Node.js install and move forward.  Of course I could just hit nodejs.org and get the new image, but figured there had to be an easier way.  It turns out there is -- you can upgrade your local Node.js with NPM:

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

The n package represents a Node helper, and running the last command upgrades node to the latest stable version.  Instead of using "stable", you could specify a desired version:

sudo n 0.8.21

Once your install is complete, you can confirm you version with another command:

node -v

It's quite nice that you can upgrade Node.js right from npm;  it's like Inception...or something.


  1. Chris Hamant March 7, 2013

    Just to be pedantic – ‘n’ isn’t something that the guys behind npm and nodejs core team created nor necessarily support.

    ‘n’ the package ‘https://github.com/visionmedia/n’ is created and maintained by the prolific TJ Holowaychuk. It’s one of many competing version managers for nodejs – https://github.com/creationix/nvm being another.

    While I do sometimes need to manage different versions of node (those tools are convenient for sure) I personally rely upon a decent package manager on my OS. ‘Homebrew’ (or MacPorts/Fink if a masochist) on OSX. ‘Chocolatey’ on Windows. (Linux users probably have it in their distro’s package manger)

    Installing via the provided packages will ensure that npm itself is up to date too (which not all other solutions do).

  2. Neat, but I prefer to build from source and install to ~/.local so I don’t have to sudo.

  3. emmmm… nvm?

  4. Santi May 22, 2013

    Anyway of doing this on windows?

  5. Didn’t work for me.. :(

  6. Thanks, this worked great for me.

    Regardless of whether ‘n’ is developed by the npm guys, I haven’t done anything special and I found it was already installed on my centos 6 system (which was set up from scratch and only has node and npm installed)

  7. Thanks David, you are a wealth of information!

  8. MattDMo August 14, 2013

    It’s nice to know about `n`, but one of its major failings (at least for me, on Linux, without ‘sudo’ privileges) is that there’s no way to define a local install path, or even one that’s not `/usr/local`. Back to building the source for me…

  9. David Beckwith August 22, 2013

    It worked nicely for me. Thank you!

  10. Thanks worked for me.

  11. Works fine thx!

  12. Did anybody get this working on Windows 7 ?
    When trying to run n (anything with n , like “n -h” or “n stable” fails saying
    ‘sh’ is not recognized as an internal or external command.

    Because in AppData\Roaming\nmp\n.cmd file there is a line trying to use sh as
    sh “%dp0\node_modules\n\bin\n” %*

    and since it does not know what sh is it does NOT work on windows 7.
    Looked at the package.json file of n , did not see any dependencies.

    What is missing ? How to get the n to work on Windows 7 ?

  13. worked for me.. cheers

  14. I’ve been using n for sometime now and like it, seems like everyone uses nvm but I like the stuff TJ makes, he’s brilliant

  15. Borislav October 21, 2013

    It worked like a charm! Thank you!

  16. Worked like a charm – cheers mate

  17. this worked cool.. thanks

  18. Yeah, trying to figure out on windows 7 too, if anybody found a way :)
    Same behavior as iliker.

  19. It worked for me… but it killed npm. That is to say, node was update but npm command stopped working. I had to reinstall node the old way to get npm working again.

  20. Worked for me, thanks Mr Walsh!

  21. Muchas gracias! funciona perfecto!

  22. Daniel Mejia January 30, 2014

    Gracias david. I found out about cache clean.

  23. Very useful and fast. Many thanks!

  24. I’m new in node development and just starting to learn from it.. I had an issue with npm add user and I decided to update node using the following command but after updating.. whenever I run node or npm I always got “Floating point exception” on my terminal. Please help.

    I’m using SUSE Linux sp1.

  25. Thanks for the info. On Windows 7 installing n worked for me but then it tells me the version it tries to install is a invalid version. Since it is the very version I get from nodejs as a installer, I’m going to just say this does not work on Windows but it’s no big deal since it’s so easy to download the installer from the website.

    Will probably use this on my Linux machines if I remember so thanks :-)

  26. Carl-Erik March 11, 2014

    Does not work on Windows 7.

    $ n stable

    install : v0.10.26

    Error: invalid version 0.10.26

  27. No version works with n in windows. They all give invalid version.

  28. marcelklehr April 5, 2014

    Hey guys.

    Just to clear things up: N doesn’t support windows. It works Unixy operating systems, but not on windows.

    If you need a node version manager for windows, try https://github.com/marcelklehr/nodist


  29. Carlos Vazquez April 15, 2014

    Thanks for the instructions, it was the only way I could have possibly pulled this out (I’ve read way too many articles)

Be Heard

Tip: Wrap your code in <pre> tags or link to a GitHub Gist!

Use Code Editor
Redacted Font
An Interview with Eric Meyer