742

I did the following to update my npm:

npm update npm -g

But I have no idea how to update Node.js. Any suggestions? (I'm using Node.js 0.4.1 and want to update to Node.js 0.6.1.)

naXa stands with Ukraine
  • 35,493
  • 19
  • 190
  • 259
alexchenco
  • 53,565
  • 76
  • 241
  • 413
  • 5
    Possible duplicate: [How can I update NodeJS and Npm for the next versions?](http://stackoverflow.com/q/6237295) . (should at the very least be linked) – blong Dec 05 '12 at 00:39
  • Possible duplicate of [Upgrading Node.js to latest version](http://stackoverflow.com/questions/10075990/upgrading-node-js-to-latest-version) – blo0p3r Jan 07 '16 at 22:09
  • 29
    I don't really get why most of the answers suggest to install third party tools :/ – mcont Jul 24 '16 at 21:35
  • Things have gotten quite a bit easier since this question was first answered (if you don't need version management) : [All platforms (Windows, Mac & Linux)](https://stackoverflow.com/a/33010229/2768271) – swelet Nov 04 '17 at 07:08
  • Possible duplicate of [How can I update Node.js and npm to the next versions?](https://stackoverflow.com/questions/6237295/how-can-i-update-node-js-and-npm-to-the-next-versions) – core114 Nov 09 '17 at 06:35

30 Answers30

1666

To upgrade Node you may first want to see which version of Node.js you are currently using:

node --version

Find out which versions of Node.js you may have installed and which one of those you're currently using:

nvm ls

List all versions of Node.js available for installation:

nvm ls-remote

Apparently for Windows the command would be rather like this:

nvm ls available

Assuming you would pick Node.js v8.1.0 for installation you'd type the following to install that version:

nvm install 8.1.0

You are then free to choose between installed versions of Node.js. So if you would need to use an older version like v4.2.0 you would set it as the active version like this:

nvm use 4.2

That should be all.


In 2013 I used the following instructions to upgrade from Node.js version 0.10.6 to 0.10.21 on a Mac, for more recent instructions see above.

Update from 2017: Please mind, Mr. Walsh himself recommended to update Node.js just using nvm instead.

  1. Clear NPM's cache:

     sudo npm cache clean -f
    
  2. Install a little helper called 'n'

     sudo npm install -g n
    
  3. Install latest stable Node.js version

     sudo n stable
    

Alternatively pick a specific version and install like this:

sudo n 0.8.20

For production environments you might want to pay attention to version numbering and be picky about odd/even numbers.

Credits

Oliver Schafeld
  • 17,358
  • 2
  • 15
  • 13
  • 157
    You should credit your source - your answer is quoted from David Walsh's blog: http://davidwalsh.name/upgrade-nodejs. It should also be noted that this method has major caveats, some rather destructive, as seen in the comments on the original blog post. – Shawn Erquhart Jun 25 '15 at 17:15
  • 4
    Unfortunately that din't worked for me.. was doing exact as described on a Linux machine - 'node -v' before and after showed 'v0.10.5' – Michael Jul 20 '15 at 09:47
  • 35
    One more step. Close and re-open terminal or if using ssh, exit and log back in to see new node-v – isimmons Jul 26 '15 at 03:30
  • Doesn't appear to work on raspberry pi B+ most likely the utility does not support the ARM version – Felipe Aug 29 '15 at 17:25
  • did not success when node installed at a customized path – Yin Oct 20 '15 at 02:51
  • clearing cache may not be necessary. @ShawnErquhart I found http://theholmesoffice.com/node-js-fundamentals-how-to-upgrade-the-node-js-version/ which seems an older article - also the answer above doesn't appear to be a straight copy unless David Walsh's blog was updated and I missed it. – Sandra Feb 09 '16 at 12:48
  • why sudo everything? – Rob Imig Apr 19 '16 at 14:21
  • 1
    @Rob Imig : Globally installed scripts usually go to places like `/usr/local/bin` that require special permissions for installation. Further information: https://github.com/npm/npm/issues/3139 A possible fix/workaround (if you really want to avoid using `sudo`): http://stackoverflow.com/questions/16724259/npm-command-sudo-or-not – Oliver Schafeld Apr 20 '16 at 07:58
  • This doesn't work for me on Linux. I get `sudo: n: command not found` for the third step. – thatWiseGuy Oct 20 '16 at 21:28
  • I already downvoted this before because it's not cross platform. However, aditionally, this also DOES NOT install latest nodejs. It installed v4 while v6.10.0 is the latest available for download. – Tomáš Zato Mar 17 '17 at 13:29
  • 5 years later, and this still works OK. I'm on Mac OS – Sylvan D Ash Jun 27 '17 at 07:42
  • 2
    Seems to work for me but just followed the link to David Walsh's Blog above and he explicitly says not to use it - be warned! – brianjlennon Jun 28 '17 at 18:16
  • 1
    Thanks brianjlennon for the hint. I updated my answer from 2013 accordingly. Including credits/links. I hope that's okay. – Oliver Schafeld Jun 30 '17 at 19:14
  • 1
    you should mention that your answer is NOT cross-platform or change it accordingly. Specifically, it is NOT working for WIndows (7, for example), that was several times mentioned other users. Whtn you change it, i will take off my downvote, and may be upvote, if i like it. – WebComer Mar 19 '18 at 20:12
  • Humm the funniest thing about force clean is when CLI prompts : `WARN using --force I sure hope you know what you are doing.` – Jason Krs Mar 29 '18 at 10:51
  • Works perfectly on Linux. Thanks! – Emanuela Colta Jun 29 '18 at 16:06
  • I know this is old but none of the other suggestions worked for me. Turned out, just clearing npm's cache worked – adam tropp Jan 16 '19 at 20:10
  • This is a good solution if you are using a Linux distribution with deprecated packages like CentOS... Otherwise using `apt upgrade` to update Node.js in Debian / Ubuntu should be fine. – baptx Jul 29 '19 at 11:50
  • You can also update to the current LTS or latest release by using `nvm install --lts` or `nvm install --latest-npm`. For those not wanting to type the version number every time. – Stephen Sabatini May 31 '20 at 23:05
  • I am getting command not found in third step – user9437856 Dec 02 '20 at 06:42
  • In order to install nvm on Windows (Win10 here), [you need a POSIX compliant shell like "BashOnWindows"](https://github.com/nvm-sh/nvm/issues/1283#issuecomment-258030997). I highly recommend just [downloading the Node installer](https://nodejs.org/en/) and running it again. This will update Node and npm. – A__ Jun 17 '22 at 00:21
  • worked like a charm on orangepi5 running armbian, had to do only one more trick because it didnt worked properly at the begin using with this answer: https://stackoverflow.com/a/63306927/3982722 – Gio Venice May 30 '23 at 20:24
700

Use Node Version Manager (NVM)

It's a Bash script that lets you download and manage different versions of node. Full source code is here.

There is a separate project for nvm for Windows: github.com/coreybutler/nvm-windows

Below are the full steps to use NVM for multiple version of node on windows

  1. download nvm-setup.zip extract and install it.
  2. execute command nvm list available from cmd or gitbash or powershell, this will list all available version of node enter image description here
  3. use command nvm install version e.g. nvm install 12.14.0 to install on the machine
  4. last once installed use nvm use version to use newer version e.g. nvm use 12.14.0
Rajnikant
  • 2,176
  • 24
  • 23
pradeek
  • 21,445
  • 2
  • 31
  • 32
  • 16
    FYI, the command to run once having install NVM is 'nvm install '. For example 'nvm install v0.8.7' – Kevin Lamping Aug 18 '12 at 13:55
  • FYI: I even used nvm on an (arm) android tablet with debian. It downloads src & builds it. I upgraded v0.6.x to v0.8.x without issue. – cmroanirgo Jan 08 '13 at 12:44
  • 18
    You don't need this. Node is not Ruby. – fiatjaf May 03 '15 at 13:00
  • I really liked NVM before iojs and npm agreed to merge back together. But now it's just a hassle for little reward. Anything that thinks it knows where your node path will be automatically will need to be configured manually. Not a huge deal but kind of annoying. – Confused Jul 25 '15 at 02:36
  • 29
    @SimonEast There is an nvm for windows: https://github.com/coreybutler/nvm-windows – Phil Hannent Nov 18 '15 at 10:45
  • 5
    @PhilHannent as per NVM github page, they don't support NVM on windows, so one can say that "there is no official NVM for windows" – Sudhanshu Mishra Nov 21 '16 at 00:07
  • 8
    For windows just download latest version and install it. It will be automatically updated to new version you downloaded. – last_fix Mar 25 '19 at 04:54
  • https://michael-kuehnel.de/node.js/2015/09/08/using-vm-to-switch-node-versions.html this is a good documentation for nvm use – gsumk Nov 25 '19 at 20:40
  • If you're using VS Code, don't forget to restart it after installing NVM – Mihail Bondarenco Mar 15 '20 at 22:52
  • 2
    you just want to install latest version of NodeJs from official site and it will automatically be updated. WHY BOTHER WITH NVM? – maverick Feb 24 '21 at 09:09
  • 1
    Thank you for this answer, it led me down the right road. A couple of notes, it works better if you uninstall node if you have installed it previously, just know you will have to reinstall Angular CLI if you had it installed. – dmoore1181 Apr 20 '21 at 18:50
  • 1
    now the list command is `nvm ls-remote` – the Hutt May 31 '22 at 17:02
616

Any OS (including Windows, Mac & Linux)

Updated October 2022


Just go to the official Node.js site (nodejs.org), download and execute the installer program.

It will take care of everything and with a few clicks of 'Next' you'll get the latest Node.js version running on your machine. Since 2020 it's the recommended way to update NodeJS. It's the easiest and least frustrating solution.

Download NodeJS for Windows, buttons

Download NodeJS for Win/Mac/Source Code buttons


Pro tips

  • NodeJS installation includes NPM (Node package manager).

  • To check your NPM version use npm version or node --version.

  • If you prefer CLI, to update NPM use npm install -g npm and then npm install -g node.

    • For more details, see the docs for install command.
  • Keep an eye on NodeJS blog - Vulnerabilities so you don't miss important security releases. Keep your NodeJS up-to-date.

  • Operating systems supported by Node.js:

  • Troubleshooting for Windows:

    If anyone gets file error 2502/2503 like myself during install, run the .msi via Administrator command prompt with command msiexec /package [node msi]


If my answer is helpful, don't forget to upvote it
(here is the original answer by Anmol Saraf, upvote it too)

naXa stands with Ukraine
  • 35,493
  • 19
  • 190
  • 259
  • 23
    So simple and obvious.. I was looking for a shortcut, but this way seems the simplest. `node --version` to check that it worked.. i had to google that too -- don't check my node version very often. – Steve Jun 30 '16 at 01:37
  • For those wondering if node modules will survive after running the newer version msi - the answer is yes! It worked for me too! – vezenkov Oct 05 '16 at 15:43
  • 2
    This didnt work for me. I have an ancient install of 0.10.26. I have been trying to install 6.10.0 LTS, but it seems impossible I can download and install 6.10.0 as many times as I want, the windows 10 machine can only see 0.10.26. In "add remove programs" I only see 6.10.0. – John Little Mar 08 '17 at 21:45
  • 16
    Why exactly would you hyperlink operating systems' wiki pages? – Buffalo Jan 25 '18 at 08:02
  • I logged to upvote this and say that it should be the accepted answer. Anyway would be nice to have a node -u with confirmation or negation. I was searching through node --help realizing very quickly that it doesn't exist. I was surprised. But anway. Download + Execute is not such a big deal. – Matthis Kohli Apr 27 '18 at 21:07
  • 25
    I prefer the CLI :D and I am a windows user. `npm install -g npm stable` then `npm install -g node` – Radmation Jun 02 '18 at 17:30
  • I did do this before I found this answer since it is not on the top, which it should. – Crismogram Aug 06 '18 at 15:29
  • 1
    As usual in windows a double click is all you need to take care of the update. Can confirm having upgraded multiple times successfully simply by downloading the latest version and installing it. – Xavi3R Elvis Oct 25 '18 at 12:48
  • 1
    As of Aug 2020 on a Mac, downloading from the node.js website seems to be the best method because "it just works". There's too many different ways to do it by CLI (just look at these answers), each those seem to have subtle conditions or unspoken assumptions, too many gotchas, and too many changes over the years. I think if you have to ask how to do this, the only answer is to download/install from node.js. Anything else is asking for confusion. – Angelo Aug 02 '20 at 13:27
  • If anyone gets file error 2502/2503 like myself during install, run the .msi via Administrator command prompt with command `msiexec /package [node msi]`. – Milo Jan 06 '21 at 16:53
  • I couldn't get the installer to work on Windows 10, installing the latest LTS version. It would always error out in PowerShell when installing the additional requirements. – BadHorsie May 26 '21 at 11:09
  • @BadHorsie did you try with elevated permissions (run PowerShell as Administrator)? – naXa stands with Ukraine May 26 '21 at 12:12
  • To check your NPM version use npm version or node --version. If you prefer CLI, to update NPM use npm install -g npm and then npm install -g node. work perfectly – preety Mar 04 '22 at 11:52
  • Worth noting that in some cases this method will require a full system reboot to the latest version fully recognized and up and running. Particularly Windows 11 seems prone to this in for one reason or another recent testing. – Jem Jun 18 '22 at 17:14
  • This is simple and quick solution, this still works on node 17 and up, thank you naXa – Two Nov 26 '22 at 11:28
459

If you have Homebrew installed (only for macOS):

$ brew upgrade node
Will
  • 5,654
  • 2
  • 23
  • 26
  • 4
    Agreed, I just run "brew upgrade" every few days and I'm kept up to date with the latest changes for all of my packages – Glen Selle Apr 08 '13 at 02:08
  • 3
    This is a pain because it means having to upgrade xcode which means having to upgrade osx... – JGallardo Dec 25 '13 at 09:15
  • 13
    Mine says node not installed. Note: I didn't install node with homebrew. Is there something else I should do? – theonlygusti Jan 10 '16 at 19:30
  • 4
    How to install specific version of node using brew ? – Shobhit Puri Apr 25 '16 at 18:45
  • 1
    Never mind, found it at http://apple.stackexchange.com/questions/171530/how-do-i-downgrade-node-or-install-a-specific-previous-version-using-homebrew – Shobhit Puri Apr 25 '16 at 18:49
  • 2
    I wrote this super early in my career, and since then have had a chance to try a bunch of different techniques. I highly recommend installing `n` and using that if you can, à la another answer on this thread: http://stackoverflow.com/a/19584407/392113 – Will Apr 18 '17 at 17:46
  • 1
    brew did some upgrade but still see the old node -v in the command line – luky Aug 24 '18 at 20:04
  • while using npx create-react-app . i had node version incompatibility and did upgrade to latest version of node with brew upgrade node. Successfully upgraded to v15.0.1 however i did also faced error with yarn saying No such file or directory -/usr/local/Cellar/yarn/1.22.4 – Shariati Oct 23 '20 at 23:31
387

2021: Just go to nodejs.org and use the latest installer.

That's it folks. It used to be more complex and people used different kinds of packages and strategies to manage it. But things have changed for the better.

Works for all platforms (Windows, Mac & Linux).

Vega
  • 27,856
  • 27
  • 95
  • 103
swelet
  • 8,192
  • 5
  • 33
  • 45
  • 9
    After Setup re-installation gulp didn't work. Then I called `npm rebuild` and it was fine again. – Beauty Feb 27 '17 at 14:01
  • 2
    This didnt work for me. I have an ancient install of 0.10.26. I have been trying to install 6.10.0 LTS, but it seems impossible I can download and install 6.10.0 as many times as I want, the windows 10 machine can only see 0.10.26. In "add remove programs" I only see 6.10.0. I cant find how to remove or update this old version, or how to install the new version over it. Any ideas? – John Little Mar 08 '17 at 21:47
  • 4
    For the last comment, you can use "where" command to find the executable. For example: "where node.exe". In my system (win10) this gives "C:\Program Files\nodejs\node.exe" – Dinesh Rajan May 25 '17 at 19:33
  • 1
    i concur, just go to nodejs.org and download and it will update everything automatically – russiansummer Jan 19 '18 at 18:23
  • 5
    I tried the other solutions to this question and this one was the easiest and least frustrating. – Jeff Marino Aug 04 '18 at 20:23
  • I had to run this after I had downloaded the new node.js from the website: `npm install -g node` – KalleP Mar 08 '19 at 08:41
  • FYI I could not get this (NPM install) working on Ubuntu 18.04.5 LTS. It would fail every time even when I chown the directories (as explained elsewhere). I also completely uninstalled my node installation, but it still wouldn't work. Finally, the only thing that I could do to get it to work was to install it via Snap. Otherwise I could only get v8.10. Snap installed v12.18.3 – raddevus Sep 08 '20 at 20:16
  • 1
    Just in case, this doesn't work for Windows 7. – Anastasia Apr 06 '21 at 13:43
205

First update npm,

npm install -g npm stable

Then update node,

npm install -g node or npm install -g n

check after version installation,

node --version or node -v

bora.oren
  • 3,439
  • 3
  • 33
  • 31
Shapi
  • 5,493
  • 4
  • 28
  • 39
  • 13
    Be aware it worked for me under Windows 2016 but node was installed into the directory of the current user: `C:\Users\my-current-user\AppData\Roaming\npm\...`; it did not update an older installation under `C:\Program Files\nodejs` nor the path variable. i ended up reinstalling with the msi-installer. that fixed it for me. – surfmuggle Aug 13 '18 at 22:45
  • 5
    This is a terrible idea. Why? Later versions of npm require later version of node. Therefore you can update npm and then it stops working as you need a newer version of node. Thus you are back to the start and now your npm is broken. – user3786992 Sep 29 '18 at 02:04
  • 1
    its installs `6.8.0` for `npm` ,but i wants `6.11` for NodeJS, is it fine to use `npm install -g npm` – Ashish Kamble Feb 15 '19 at 12:34
  • After this we need to change symlink `ln -sf /usr/local/n/versions/node/10.17.0/bin/node /usr/bin/node` – Vinod Sai Nov 15 '19 at 17:10
  • As with @surfmuggle the above method wrongly installed node into `C:\Users\my-current-user\AppData\Roaming\npm`. To fix: I deleted that directory (`npm`) and removed it from my Windows Path. Then the command `node -v` would work to pickup the right node version installed from https://nodejs.org/en/download/. – John Bentley Dec 11 '21 at 15:15
  • This gave me the following warning `Node.js version v19.6.1 detected. Odd numbered Node.js versions will not enter LTS status and should not be used for production. For more information, please see https://nodejs.org/en/about/releases/.` And `npm install` just freezes – Paul Mar 08 '23 at 18:24
153

On Windows you can use Chocolatey to install and update Node.js (and lots of other packages).

Install Node

cinst nodejs.install

Update Node

cup nodejs.install

Note: You will need to install Chocolatey before you can use cinst and cup.

naXa stands with Ukraine
  • 35,493
  • 19
  • 190
  • 259
rob
  • 17,995
  • 12
  • 69
  • 94
  • 1
    I was getting: _The schema version of 'Microsoft.AspNet.Mvc' is incompatible with version 2.1.31022.9038 of NuGet. Please upgrade NuGet to the latest version from http://go.microsoft.com/fwlink/?LinkId=213942._ When I tried to run the **cup nodejs.install**. Found that if I run **nuget.exe update -self** on the nuget.exe in the C:\Chocolatey\chocolateyinstall directory. Hope this helps anyone out there. – Aaron P. Olds Sep 25 '14 at 18:45
  • 1
    `cinst nodejs.install` Chocolatey (v0.9.8.27) is installing 'nodejs.install' and dependencies. By installing you accept the license for 'nodejs.install' and each dependency you are installing. Unable to find package 'nodejs.install'. Command 'install' failed (sometimes this indicates a partial failure). Additional info/packages: nodejs.install – Frederik Krautwald Oct 18 '14 at 00:19
  • 25
    I feel a question about how you update Chocolatey coming on. – Martin Brown Sep 27 '16 at 18:55
  • 1
    What's the difference between `nodejs.install` and `nodejs`? – Ohad Schneider Nov 16 '17 at 16:49
  • 6
    @OhadSchneider if you use `.install` then you will be able to uninstall node from "Apps & features" in windows – rob Nov 16 '17 at 21:31
  • On windows I recommend using winget [microsoft winget page](https://learn.microsoft.com/en-us/windows/package-manager/winget/). For me it's the smoothest experience I had with managing apps on windows. To upgrade node type `winget upgrade Node.js` – Broccoli Feb 12 '23 at 16:42
107

To upgrade node to the latest version or to a specific version you can do the following:

sudo npm install n -g
sudo n 0.10.18   // This will give you the specific version

For the latest stable version:

sudo n stable

For the latest LTS version(Tested on Mac)

sudo n lts
Krishnadas PC
  • 5,981
  • 2
  • 53
  • 54
user1429844
  • 1,137
  • 2
  • 8
  • 6
  • 2
    Could you not do this in 2011? Why did everybody else answer with external solutions? +1 for using NPM and deserves answer IMO. – Erik Reppen Oct 19 '13 at 23:55
  • 2
    Worked for me on an AWS EC2 Linux instance – ChrisRich Oct 06 '15 at 23:51
  • 2
    If you are trying to install "n" on windows, do not waste your time. At this time, still, "n" does not run on windows. For windows you either have to update from the installers on nodejs.org, use npm `npm install -g node``, use chocolaty, or install nvm (a third party version manager for node). – Paul Stoner Apr 22 '20 at 15:18
  • @ErikReppen n is a node package. This counts as "external" for me. – Leif Dec 09 '20 at 15:34
92

To control your version of Node.js, you can try n. I found it very straightforward and useful.

n is a Node.js binary management, no subshells, no profile setup, no convoluted API, just simple.

npm install -g n

n 0.6.19 will install Node.js v0.6.19.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Clément Renaud
  • 2,320
  • 18
  • 13
  • 3
    Also you can switch between different nodejs versions, just type "n" and select version you need – Mikhail.Mamaev Mar 12 '13 at 12:13
  • 4
    I couldn't get it to work on Windows either. The author should publish that fact. It was a dead end for me. – Tim Hardy Jun 26 '13 at 17:25
  • 1
    It works for me in Windows within the git bash shell. So if you use git fire up git bash and try it there! – Aaron Silverman Feb 02 '14 at 16:33
  • 11
    Doesn't work on Win7 for me - even in git bash. `npm ERR! notsup Not compatible with your operating system or architecture: n@1.2.9 npm ERR! notsup Valid OS: !win32 npm ERR! notsup Valid Arch: any npm ERR! notsup Actual OS: win32` – mwotton Sep 19 '14 at 00:36
  • @backdesk on windows the upgrade process is almost the same as this install process. Full instructions here: http://exponential.io/blog/install-or-upgrade-nodejs-on-windows/ – Edd Oct 01 '15 at 08:57
  • Git bash **does not** work for me on Windows 7, 64 bit OS. – Jason Jackson Oct 17 '15 at 23:09
  • 4
    Git bash **does not** work for me on Windows 10, 64 bit OS – eddyparkinson Jan 14 '16 at 01:14
  • Ugh! Running this on an ARM processor, it says it's fetching a file that has the text "x86" in the title... and then promptly dies saying it cannot execute binary file (well duh!) – Michael Feb 23 '17 at 22:16
  • This does not work on linux either, it downloads the correct version but doesn't install it: http://pastebin.com/u708hRp9 – Tomáš Zato Mar 17 '17 at 13:32
  • This is the best way to go if `n` will run on your machine. – Will Apr 18 '17 at 17:47
  • This doesn't work on my current version on node 17, but thanks anyway – Two Nov 26 '22 at 11:24
63

Short answer:

Go to this page: Download | Node.js

Download the installer for your platform, then install it.

vvvvv
  • 25,404
  • 19
  • 49
  • 81
haotang
  • 5,520
  • 35
  • 46
55

I had the same problem, when I saw that my Node.js installation is outdated.

These few lines will handle everything (for Ubuntu):

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

After this node -v will return you the latest available version.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Salvador Dali
  • 214,103
  • 147
  • 703
  • 753
23

On CentOS 7 you can do the following:

sudo npm cache clean -f
sudo npm install -g n
sudo n stable
sudo ln -sf /usr/local/n/versions/node/5.4.1/bin/node /usr/bin/node
node –v (Should show updated version now)
npm rebuild node-sass (Optional: if you use this)

Note: The symlink is required to link your node binary with the latest Node.js installed binary file.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
crmpicco
  • 16,605
  • 26
  • 134
  • 210
  • 2
    worked for me, important thing that I missed before was a symbolic linking. – Yauhen Jan 20 '16 at 17:36
  • Note that EPEL7 as of now has the latest long term stable version, so these steps are only recommended if you want something newer. – nponeccop Nov 13 '16 at 18:42
  • node –v module.js:473 throw err; ^ Error: Cannot find module '/root/test/–v' – Alexey Sh. Sep 29 '17 at 03:41
  • n latest /usr/bin/n: line 263: which: command not found /usr/bin/n: line 263: which: command not found – Alexey Sh. Sep 29 '17 at 03:43
  • @AlexeySh. It worked for me and apparently at least 16 other people. – crmpicco Mar 27 '18 at 01:32
  • For windows:-The NPM team officially recommends this method of updating Node. (source below) https://matthewhorne.me/how-to-update-npm-on-windows-10/ 1.First, open PowerShell as administrator and run the following command. >Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force >npm install -g npm-windows-upgrade >npm-windows-upgrade – Venkatesh Aug 29 '19 at 17:45
14

For OS X, I had v5.4.1 and needed the latest version 6 so I went to the Node.js homepage and clicked on one of the links below:

Node.js OS X download links

I then followed the installer and then I magically had the latest version of Node.js and npm.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
iamyojimbo
  • 4,233
  • 6
  • 32
  • 39
9

You may use nvm.

  1. Check what is the latest version at http://nodejs.org/ (e.g. v0.10.26)
  2. Run nvm install v0.10.26

Done.

You can choose which version to run:

nvm ls list the available versions and tells you which version you are using now.

nvm use VERSION change the current node to the requested version.

nvm alias default VERSION set the default version. The next time you source nvm.sh, this will be the version loaded (note that it doesn't change the version in use right now, run nvm use for that).

Riccardo Galli
  • 12,419
  • 6
  • 64
  • 62
9

For macOS in 2018+ (as ALL of the solutions above are failing for me):

Simply go to the official nodejs site, download the official nodejs package and install it by double clicking. It's the most simple, safe and always-working thing you can do.

Sliq
  • 15,937
  • 27
  • 110
  • 143
8

Some Linux distributions such as Arch Linux have Node.js in their package repositories. On such systems it is better to use a standard package update procedure, such as pacman -Suy or analogous apt-get or yum commands.

As of now (Nov 2016) EPEL7 offers a pretty recent version of Node.js (6.9.1 which is an up-to-date LTS version offered on the Node.js home page). So on CentOS 7 and derivatives you can just add EPEL repository by yum install epel-release and yum install nodejs.

CentOS 6/EPEL6 has 0.10.x which isn't supported upstream since Oct 2016.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
nponeccop
  • 13,527
  • 1
  • 44
  • 106
7

Today I ran on a Windows Git Bash:

$ npm i node -g

and got the following output:

> node@10.6.0 preinstall C:\Users\X\AppData\Roaming\npm\node_modules\node
> node installArchSpecificPackage

+ node-win-x64@10.6.0
added 1 package and audited 1 package in 23.368s
found 0 vulnerabilities

C:\Users\X\AppData\Roaming\npm\node -> C:\Users\X\AppData\Roaming\npm\node_modules\node\bin\node
+ node@10.6.0
added 2 packages from 1 contributor in 26.089s

Read more about it at https://www.npmjs.com/package/node.

Fuhrmanator
  • 11,459
  • 6
  • 62
  • 111
6

The easy way to update node and npm :

npm install -g npm@latest

download the latest version of node js and update /install

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
5
$ npm install -g npm stable

worked for me to update npm

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
Karthiga
  • 859
  • 2
  • 17
  • 33
5
Faisal Hassan
  • 396
  • 6
  • 9
  • NB: This will copy nvm.sh to your home directory. You should then run `source ~/.nvm/nvm.sh` to set up the nvm command. Now you you can run `nvm ls`, etc as listed above. This is only necessary if you do not want to have to re-open your terminal, e.g. if you are SSH'd into a remote server. – Tash Pemhiwa Aug 10 '20 at 08:06
4

For Ubuntu:

sudo apt-get install -y curl
curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash -
sudo apt-get install -y nodejs

Source: https://askubuntu.com/questions/426750/how-can-i-update-my-nodejs-to-the-latest-version

Community
  • 1
  • 1
Bruno Paulino
  • 5,611
  • 1
  • 41
  • 40
  • 1
    `curl {anything} | sudo bash -` can't possibly be a good security practice... Even leaving sophisticated attacks aside, what if you misspell the domain name? – krubo Jun 25 '19 at 20:37
  • Your comment adds no value to the answer. You can also misspell your bank domain and leak your bank details in a fake bank website. – Bruno Paulino Jul 12 '19 at 07:29
  • Do not do `npm i n -g` afterwards to update node, because then you get two nodes on your system. Stay with this update process of `apt`. Alternatively you can try `snap` which also has a built-in update function – Timo Mar 19 '21 at 08:22
4

You may use Chocolatey on Windows. It's very easy to use and useful for keeping you updated with other applications too.

Also, you can just simply download the latest version from https://nodejs.org and install it.

Will
  • 24,082
  • 14
  • 97
  • 108
Andre Morata
  • 307
  • 3
  • 12
  • 1
    He asked "I did the following to update my npm: "npm update npm -g" But I have no idea how to update node.js. Any suggestions? (I'm using node.js 0.4.1 and want to update to node.js 0.6.1)." and I suggested him to use Chocolatey to simplify the process but I also suggested him to download the latest version from the site and install it, wich is more than enough to update the nodeJS as he asked. So, I think my answer does provide a satisfactory solution for his question. – Andre Morata Mar 25 '16 at 22:47
4

According to Nodejs Official Page, you can install&update new node version on windows using Chocolatey or Scoop

Using(Chocolatey):

cinst nodejs
# or for full install with npm
cinst nodejs.install

Using(Scoop):

scoop install nodejs

Also you can download the Windows Installer directly from the nodejs.org web site

Mostafa
  • 815
  • 1
  • 13
  • 23
3

As some of you already said, the easiest way is to update Node.js through the Node.js package manager, npm. If you are a Linux (Debian-based in my case) user I would suggest to add these lines to your .bashrc file (in home directory):

function nodejsupdate() {
    ARGC=$#
    version=latest
    if [ $ARGC != 0 ]; then
        version=$1
    fi
    sudo npm cache clean -f
    sudo npm install -g n
    sudo n $version
}

Restart your terminal after saving and write nodejsupdate to update to the latest version of Node.js or nodejsupdate v6.0.0 (for example) to update to a specific version of Node.js.

BONUS: Update npm (add these lines to .bashrc)

function npmupdate() {
    sudo npm i npm -g
}

After restarting the terminal write npmupdate to update your node package manager to the latest version.

Now you can update Node.js and npm through your terminal (easier).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
AlFra
  • 379
  • 1
  • 6
  • 17
3

In windows download the node executable file from the website and install it. this worked for me.

tfa
  • 1,643
  • 16
  • 18
1

All you need to version update of Node.js:

$ brew install node

If you don't have Homebrew; please go http://brew.sh/.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
superdem
  • 15
  • 1
  • 4
0

Just install the new version over the current folder. I upgraded mine from v4.x to v6.10 on Windows.

Kelvin Yeo
  • 102
  • 1
  • 7
-3
  1. npm clean cache - you forget to clean ur cache

  2. npm update -g

    This works on mine Windows, I hope it will also work for you :D

Community
  • 1
  • 1
-4

If you want to update Node.js, just try

npm update

from your Windows cmd prompt.

Else if you want to update any specific package try

npm update <package_name>

Example:

npm update phonegap
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Amol Ghotankar
  • 2,008
  • 5
  • 28
  • 42
-10

open cmd and type

npm i -g npm
eyllanesc
  • 235,170
  • 19
  • 170
  • 241