如何在 Windows 上升级 node.js?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11699215/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to upgrade node.js on Windows?
提问by powerboy
I already have Node.js v0.8.0 running on Windows. Can I just run the latest installer to upgrade it to v0.8.4? I am afraid it will break existing third party modules on my machine.
我已经在 Windows 上运行了 Node.js v0.8.0。我可以运行最新的安装程序将其升级到 v0.8.4 吗?恐怕它会破坏我机器上现有的第三方模块。
采纳答案by Benjen
Yes, you just install the latest version. Generally you shouldn't have any compatibility problems if you are already using the same major version (e.g. Version 0.8.x). If you are concerned about changes, you can always check the changelog for each version (link to changelog is on node.js download page at nodejs.org). That should tell you of any big changes (i.e API changes, etc).
是的,您只需安装最新版本。如果您已经在使用相同的主要版本(例如版本 0.8.x),通常您不应该有任何兼容性问题。如果您担心更改,您可以随时查看每个版本的更改日志(更改日志链接位于 nodejs.org 上的 node.js 下载页面)。这应该会告诉您任何重大更改(即 API 更改等)。
回答by hashchange
For the record, I have just gone through the process, and it is painless even if you upgrade to another major version.
为了记录,我刚刚完成了这个过程,即使你升级到另一个主要版本也没有痛苦。
I have moved from 0.8 to 0.10, using the .msi package, overwriting the one installed on my system. Package problems were all fixed with npm update -g. Worked like a charm.
我已经从 0.8 移动到 0.10,使用 .msi 包,覆盖了我系统上安装的那个。包问题都用npm update -g. 像魅力一样工作。
In case it does not work like a charm:
如果它不像魅力一样工作:
npm cache cleanusually fixes the problem. Once the cache is empty, just run npm update -gagain.
npm cache clean通常可以解决问题。一旦缓存为空,只需npm update -g再次运行。
In case you really run into trouble:
如果您真的遇到麻烦:
Delete the modules you have installed globally, then reinstall them. Here's how:
删除全局安装的模块,然后重新安装它们。就是这样:
Take stock of what you have:
npm list -g --depth=0lists all top-level packages, with version numbers.npm list -g --parseable --depth=0 > npm-global-modules.txtwrites them to a file in your cwd.Any strange stuff you didn't install yourself has probably been installed by another module (rare, but I have seen it happen). Remove those modules from the list. Also remove the module "npm".
In an editor, format the output for the command line by replacing
\n?[^\n]+[\\/](regex) with a single space.(I didn't get this to work with
findstrin a pipe, hence the roundtrip to the editor. You can also do it manually, of course ;)Delete all modules. On Windows, delete (or rename) the
%appdata%\npmdirectory. For other OS, see Command to remove all npm modules globally?Reinstall the modules with
npm install -g [your module list here]. Don't forget tonpm cache cleanbefore you do it.
盘点你所拥有的:
npm list -g --depth=0列出所有顶级包,以及版本号。npm list -g --parseable --depth=0 > npm-global-modules.txt将它们写入您的 cwd 中的文件。你没有安装的任何奇怪的东西都可能被另一个模块安装了(很少见,但我已经看到它发生了)。从列表中删除这些模块。还要删除模块“npm”。
在编辑器中,通过用
\n?[^\n]+[\\/]单个空格替换(regex) 来格式化命令行的输出。(我没有
findstr在管道中使用它,因此需要往返编辑器。当然,您也可以手动完成;)删除所有模块。在 Windows 上,删除(或重命名)
%appdata%\npm目录。对于其他操作系统,请参阅命令以全局删除所有 npm 模块?重新安装模块
npm install -g [your module list here]。npm cache clean在你做之前不要忘记。
回答by rdrey
I don't have experience with node on Windows, but I have just upgraded node & modules on my Mac, so this is just a general answer:
我没有在 Windows 上使用节点的经验,但我刚刚在 Mac 上升级了节点和模块,所以这只是一个通用的答案:
If you install v0.8, you might break your existing node modules, if they use deprecated functions, etc. The problem is that npm only checks your version of node while modules are being installed, not at run-time.
如果您安装 v0.8,您可能会破坏现有的节点模块,如果它们使用已弃用的功能等。问题是 npm 仅在安装模块时检查您的节点版本,而不是在运行时。
To be on the safe side, you need to find the global node_modules folder on your machine, back it up to somewhere, then delete and reinstall the modules. You will need to do the same thing for the node_modules folders in the apps you are using. (Assuming you have package.json files, reinstalling these should be easy.)
为了安全起见,您需要在您的机器上找到全局 node_modules 文件夹,将其备份到某个地方,然后删除并重新安装模块。您需要对正在使用的应用程序中的 node_modules 文件夹执行相同的操作。(假设您有 package.json 文件,重新安装这些文件应该很容易。)
In practice, I don't think any of the modules I was using were actually incompatible. Good luck.
实际上,我不认为我使用的任何模块实际上是不兼容的。祝你好运。
回答by ebohlman
Unless you're using a module that relies on an actual bug that was present in 0.8.0 and was fixed by 0.8.4, you're OK. There were no API changes in between those two versions (and the node team is too smart to introduce such changes in a minor release).
除非您使用的模块依赖于 0.8.0 中存在并由 0.8.4 修复的实际错误,否则您没问题。这两个版本之间没有 API 更改(节点团队太聪明了,不会在次要版本中引入此类更改)。
回答by Daniel Rodas
Currently upgrading to 4.4.*. I just used to installer from the nodejs.org website and that upgraded everything works just fine.
目前升级到 4.4.*。我只是习惯于从 nodejs.org 网站安装程序,升级后一切正常。
回答by Jitendra Pawar
Just go to nodejs site& download it. You can install it directly without any hesitation. If you have any dependency on earlier version then check change logs.
只需转到nodejs 站点并下载它。您可以毫不犹豫地直接安装它。如果您对早期版本有任何依赖性,请检查更改日志。
回答by Ishara Amarasekera
Yes. You can upgrade your node.js version to the latest by running the installer for latest node.js version at https://nodejs.org/en/. I upgraded mine from 4.4.4 to 8.11.2 running the installer.
是的。您可以通过在https://nodejs.org/en/运行最新 node.js 版本的安装程序,将 node.js 版本升级到最新版本。我运行安装程序将我的从 4.4.4 升级到 8.11.2。
回答by B T
Best way to install node on windows is by using nvm-windows, so you can quickly switch between versions if you need to. This is analogous to the best way of installing node on linux and max, ie with nvm.
在 Windows 上安装 node 的最佳方法是使用nvm-windows,因此您可以根据需要在版本之间快速切换。这类似于在 linux 和 max 上安装节点的最佳方式,即使用nvm。
But Benjen is right (how could he not be with all his scouting experience) that you can just install a different version of node, and your version will update. Your npm dependencies may have to be reinstalled, and any extensions that aren't managed by npm may need to be recompiled, but this will be true no matter how you change your node version.
但是 Benjen 是对的(他怎么可能没有他所有的侦察经验),您只需安装不同版本的节点,您的版本就会更新。您的 npm 依赖项可能需要重新安装,并且任何不受 npm 管理的扩展都可能需要重新编译,但无论您如何更改节点版本,这都是正确的。

