简体   繁体   English

如何在 Windows 上升级 node.js?

[英]How to upgrade node.js on Windows?

I already have Node.js v0.8.0 running on Windows.我已经在 Windows 上运行了 Node.js v0.8.0。 Can I just run the latest installer to upgrade it to v0.8.4?我可以只运行最新的安装程序将其升级到 v0.8.4 吗? I am afraid it will break existing third party modules on my machine.恐怕它会破坏我机器上现有的第三方模块。

Yes, you just install the latest version.是的,您只需安装最新版本。 Generally you shouldn't have any compatibility problems if you are already using the same major version (eg Version 0.8.x).如果您已经在使用相同的主要版本(例如版本 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).如果您担心更改,您可以随时查看每个版本的变更日志(变更日志的链接在 nodejs.org 的 node.js 下载页面上)。 That should tell you of any big changes (ie API changes, etc).这应该告诉您任何重大变化(即 API 变化等)。

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.我已经从 0.8 移动到 0.10,使用 .msi 包,覆盖我系统上安装的那个。 Package problems were all fixed with npm update -g .软件包问题全部通过npm update -g修复。 Worked like a charm.工作起来很有魅力。

In case it does not work like a charm:万一它不起作用:

npm cache clean usually fixes the problem. npm cache clean通常可以解决问题。 Once the cache is empty, just run npm update -g again.一旦缓存为空,再次运行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=0 lists all top-level packages, with version numbers.盘点你拥有的东西: npm list -g --depth=0列出所有顶级包,带有版本号。 npm list -g --parseable --depth=0 > npm-global-modules.txt writes them to a file in your cwd. npm list -g --parseable --depth=0 > npm-global-modules.txt将它们写入您的 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".同时删除模块“npm”。

  • In an editor, format the output for the command line by replacing \n?[^\n]+[\\/] (regex) with a single space.在编辑器中,通过将\n?[^\n]+[\\/] (正则表达式)替换为单个空格来格式化命令行的输出。

    (I didn't get this to work with findstr in a pipe, hence the roundtrip to the editor. You can also do it manually, of course;) (我没有让它在管道中与findstr一起工作,因此往返于编辑器。当然,您也可以手动完成;)

  • Delete all modules.删除所有模块。 On Windows, delete (or rename) the %appdata%\npm directory.在 Windows 上,删除(或重命名) %appdata%\npm目录。 For other OS, see Command to remove all npm modules globally?对于其他操作系统,请参阅全局删除所有 npm 模块的命令?

  • Reinstall the modules with npm install -g [your module list here] .使用npm install -g [your module list here]重新安装模块。 Don't forget to npm cache clean before you do it.在执行之前不要忘记npm cache clean

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.为了安全起见,您需要在您的机器上找到全局 node_modules 文件夹,将其备份到某个地方,然后删除并重新安装模块。 You will need to do the same thing for the node_modules folders in the apps you are using.您需要对正在使用的应用程序中的 node_modules 文件夹执行相同的操作。 (Assuming you have package.json files, reinstalling these should be easy.) (假设您有 package.json 文件,重新安装这些文件应该很容易。)

In practice, I don't think any of the modules I was using were actually incompatible.实际上,我不认为我使用的任何模块实际上是不兼容的。 Good luck.祝你好运。

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/ .您可以通过在https://nodejs.org/en/运行最新 node.js 版本的安装程序,将您的 node.js 版本升级到最新版本。 I upgraded mine from 4.4.4 to 8.11.2 running the installer.我将我的从 4.4.4 升级到运行安装程序的 8.11.2。

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.除非你使用的模块依赖于 0.8.0 中存在并由 0.8.4 修复的实际错误,否则你没问题。 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).这两个版本之间没有 API 更改(节点团队太聪明了,不会在次要版本中引入此类更改)。

Currently upgrading to 4.4.*.目前正在升级到 4.4.*。 I just used to installer from the nodejs.org website and that upgraded everything works just fine.我只是习惯从 nodejs.org 网站安装程序,升级后一切正常。

Just go to nodejs site & download it.只需转到nodejs 站点并下载它。 You can install it directly without any hesitation.您可以毫不犹豫地直接安装它。 If you have any dependency on earlier version then check change logs.如果您对早期版本有任何依赖,请检查更改日志。

Best way to install node on windows is by using nvm-windows , so you can quickly switch between versions if you need to.在 Windows 上安装节点的最佳方法是使用nvm-windows ,因此您可以根据需要在版本之间快速切换。 This is analogous to the best way of installing node on linux and max, ie with nvm .这类似于在 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.但是 Benjen 是对的(他怎么可能没有他所有的球探经验)你可以安装不同版本的节点,你的版本会更新。 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.您的 npm 依赖项可能必须重新安装,并且任何不受 npm 管理的扩展都可能需要重新编译,但无论您如何更改节点版本,都是如此。

JUST GO TO就去

nodejs.org nodejs.org

INSTALL THE LATEST STABLE VERSION (Recommended For Most Users)安装最新的稳定版本(推荐给大多数用户)

and then run然后运行

npm install node

Now, you are good to go现在,你可以开始了

You can even check the version of NodeJS using command您甚至可以使用命令检查 NodeJS 的版本

node --version

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM