如何更新 Node.js?

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.)

转载于:https://stackoverflow.com/questions/8191459/how-do-i-update-node-js

csdnceshi67
bug^君 npm update npm -g works fine from cmd, what the complain is about :)
接近 3 年之前 回复
weixin_41568127
?yb? Possible duplicate of How can I update Node.js and npm to the next versions?
接近 3 年之前 回复
weixin_41568110
七度&光 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)
接近 3 年之前 回复
csdnceshi53
Lotus@ Please refer this site, hostingadvice.com/how-to/update-node-js-latest-version it includes all methods to update the node
3 年多之前 回复
weixin_41568183
零零乙 Mortensen has really been going to town on the posts here...
接近 4 年之前 回复
csdnceshi76
斗士狗 I don't really get why most of the answers suggest to install third party tools :/
大约 4 年之前 回复
csdnceshi62
csdnceshi62 Possible duplicate of Upgrading Node.js to latest version
接近 5 年之前 回复
csdnceshi74
7*4 Possible duplicate: How can I update NodeJS and Npm for the next versions? . (should at the very least be linked)
接近 8 年之前 回复

29个回答

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

csdnceshi65
larry*wei Should this really be the selected answer? I don't think so.
大约 2 年之前 回复
weixin_41568184
叼花硬汉 as per NVM github page, they don't support NVM on windows, so one can say that "there is no official NVM for windows"
接近 4 年之前 回复
csdnceshi74
7*4 Oh excellent! I stand corrected. Thanks for the link.
接近 5 年之前 回复
weixin_41568183
零零乙 There is an nvm for windows: github.com/coreybutler/nvm-windows
接近 5 年之前 回复
csdnceshi74
7*4 NVM does not support Windows at all.
大约 5 年之前 回复
weixin_41568196
撒拉嘿哟木头 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.
大约 5 年之前 回复
csdnceshi51
旧行李 You don't need this. Node is not Ruby.
5 年多之前 回复
csdnceshi60
℡Wang Yan This works for me, davidwalsh.name/upgrade-nodejs
6 年多之前 回复
weixin_41568134
MAO-EYE 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.
接近 8 年之前 回复
csdnceshi61
derek5. FYI, the command to run once having install NVM is 'nvm install <version>'. For example 'nvm install v0.8.7'
大约 8 年之前 回复

This is a simple solution that works for all supported operating systems* including Windows:

After a lot of surfing and not finding a straight solution, I just tried going to Node.js site, clicked the DOWNLOADS button on homepage and executed the installer program (MSI).

Thankfully it took care of everything and with a few clicks of 'Next' button I got the latest Node.js version running on my Windows machine.

(here is the original answer)

For Docker users, here's the official Node.js image.


PS: To check your Node version use npm version or node --version.
PPS: Keep an eye on NodeJS blog - Vulnerabilities so you don't miss important security releases.

* Operating systems supported by Node.js: Windows, Linux, MacOS, SunOS, IBM AIX

csdnceshi50
三生石@ 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.
接近 2 年之前 回复
csdnceshi69
YaoRaoLov I did do this before I found this answer since it is not on the top, which it should.
大约 2 年之前 回复
csdnceshi67
bug^君 I prefer the CLI :D and I am a windows user. npm install -g npm stable then npm install -g node
2 年多之前 回复
csdnceshi78
程序go 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.
2 年多之前 回复
weixin_41568126
乱世@小熊 Why exactly would you hyperlink operating systems' wiki pages?
2 年多之前 回复
weixin_41568183
零零乙 sorry to here that. Have you tried to add a path to NodeJS to the PATH environment variable?
3 年多之前 回复
csdnceshi58
Didn"t forge 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.
3 年多之前 回复
csdnceshi57
perhaps? For those wondering if node modules will survive after running the newer version msi - the answer is yes! It worked for me too!
大约 4 年之前 回复
csdnceshi55
~Onlooker 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.
4 年多之前 回复

I used the following instructions to upgrade from Node.js version 0.10.6 to 0.10.21 on a Mac.

  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


Update (June 2017):

This four years old post still receives up-votes so I'm guessing it still works for many people. However, Mr. Walsh himself recommended to update Node.js just using nvm instead.

So here's what you might want to do today:

Find out which version of Node.js you are 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
csdnceshi75
衫裤跑路 You saved a day. Thanks man !!
大约 2 年之前 回复
csdnceshi74
7*4 Works perfectly on Linux. Thanks!
2 年多之前 回复
csdnceshi56
lrony* Humm the funniest thing about force clean is when CLI prompts : WARN using --force I sure hope you know what you are doing.
2 年多之前 回复
weixin_41568134
MAO-EYE i've followed haotang answer and it's succesful!
2 年多之前 回复
weixin_41568134
MAO-EYE 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.
2 年多之前 回复
weixin_41568127
?yb? Thanks brianjlennon for the hint. I updated my answer from 2013 accordingly. Including credits/links. I hope that's okay.
3 年多之前 回复
weixin_41568131
10.24 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!
3 年多之前 回复
csdnceshi64
游.程 5 years later, and this still works OK. I'm on Mac OS
3 年多之前 回复
csdnceshi60
℡Wang Yan 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.
3 年多之前 回复
csdnceshi58
Didn"t forge This worked for me in Ubuntu 16.04 LTS. Thank you.
接近 4 年之前 回复
csdnceshi72
谁还没个明天 This doesn't work for me on Linux. I get sudo: n: command not found for the third step.
大约 4 年之前 回复
weixin_41568127
?yb? Imig : Globally installed scripts usually go to places like /usr/local/bin that require special permissions for installation. Further information: github.com/npm/npm/issues/3139 A possible fix/workaround (if you really want to avoid using sudo): stackoverflow.com/questions/16724259/npm-command-sudo-or-not
4 年多之前 回复
weixin_41568196
撒拉嘿哟木头 why sudo everything?
4 年多之前 回复
csdnceshi76
斗士狗 clearing cache may not be necessary. @ShawnErquhart I found theholmesoffice.com/… 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.
4 年多之前 回复
csdnceshi50
三生石@ did not success when node installed at a customized path
大约 5 年之前 回复
csdnceshi68
local-host Doesn't appear to work on raspberry pi B+ most likely the utility does not support the ARM version
大约 5 年之前 回复
csdnceshi62
csdnceshi62 One more step. Close and re-open terminal or if using ssh, exit and log back in to see new node-v
大约 5 年之前 回复
csdnceshi53
Lotus@ 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'
5 年多之前 回复
csdnceshi63
elliott.david You should credit your source - your answer is quoted from David Walsh's blog: 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.
5 年多之前 回复
csdnceshi54
hurriedly% Does not work on Windows.
大约 6 年之前 回复

All platforms (Windows, Mac & Linux)

Just go to nodejs.org and download the latest installer. It couldn't be any simpler honestly, and without involvement of any third-party stuff. It only takes a minute and does not require you to restart anything or clean out caches, etc.

I've done it via npm a few times before and have run into a few issues. Like for example with the n-package not using the latest stable release.

weixin_41568131
10.24 I tried the other solutions to this question and this one was the easiest and least frustrating.
大约 2 年之前 回复
csdnceshi67
bug^君 i concur, just go to nodejs.org and download and it will update everything automatically
接近 3 年之前 回复
csdnceshi75
衫裤跑路 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"
3 年多之前 回复
csdnceshi53
Lotus@ 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?
3 年多之前 回复
csdnceshi79
python小菜 After Setup re-installation gulp didn't work. Then I called npm rebuild and it was fine again.
3 年多之前 回复

If you have Homebrew installed (only for OS X):

$ brew upgrade node
csdnceshi59
ℙℕℤℝ brew did some upgrade but still see the old node -v in the command line
大约 2 年之前 回复
csdnceshi71
Memor.の Thanks, this is the best way on mac
大约 3 年之前 回复
csdnceshi54
hurriedly% 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: stackoverflow.com/a/19584407/392113
3 年多之前 回复
csdnceshi52
妄徒之命 Don't forget to run brew update first
4 年多之前 回复
csdnceshi51
旧行李 Never mind, found it at apple.stackexchange.com/questions/171530/…
4 年多之前 回复
csdnceshi51
旧行李 How to install specific version of node using brew ?
4 年多之前 回复
csdnceshi73
喵-见缝插针 Mine says node not installed. Note: I didn't install node with homebrew. Is there something else I should do?
接近 5 年之前 回复
weixin_41568131
10.24 This is a pain because it means having to upgrade xcode which means having to upgrade osx...
接近 7 年之前 回复
csdnceshi50
三生石@ 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
7 年多之前 回复
csdnceshi55
~Onlooker this probably is the best way to do it on mac...
接近 8 年之前 回复

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.

csdnceshi54
hurriedly% if you use .install then you will be able to uninstall node from "Apps & features" in windows
接近 3 年之前 回复
weixin_41568183
零零乙 What's the difference between nodejs.install and nodejs?
接近 3 年之前 回复
csdnceshi52
妄徒之命 I feel a question about how you update Chocolatey coming on.
大约 4 年之前 回复
csdnceshi59
ℙℕℤℝ 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
大约 6 年之前 回复
csdnceshi75
衫裤跑路 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 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.
大约 6 年之前 回复

Short & stupid answer:

Go to this page: Download | Node.js

Download the installer for your platform, then install it.

csdnceshi53
Lotus@ nvm is the best solution
接近 3 年之前 回复
weixin_41568184
叼花硬汉 I revised the answer to say "Download the installer for your platform" instead. You're welcome :) @AshishRatan there are Linux binaries on the same page.
接近 3 年之前 回复
csdnceshi76
斗士狗 The OP have not mentioned anything about the platform, so the MSI answer is valid.
3 年多之前 回复
weixin_41568183
零零乙 Not only for Windows, also on Mac this is the quickest
4 年多之前 回复
csdnceshi79
python小菜 Ofcourse not -.- .msi = windows
接近 5 年之前 回复
csdnceshi53
Lotus@ can you run it on ubuntu/LINUX ??
接近 5 年之前 回复

chocolately was alredy installed on my windows

i followed rob's answer

cinst nodejs.install

after a few minutes latest node is installed

enter image description here

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.

共29条数据 1 3 尾页
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐