如何在Windows上更新npm?

本文翻译自:How can I update npm on Windows?

I tried this : 我试过这个

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

...but it didn't work. ......但它没有用。

How do I do this on Windows? 我如何在Windows上执行此操作?


#1楼

参考:https://stackoom.com/question/1FFpp/如何在Windows上更新npm


#2楼

Download and run the latest MSI. 下载并运行最新的MSI。 The MSI will update your installed node and npm. MSI将更新您安装的节点和npm。


#3楼

The previous answers will work installing a new version of Node.js (probably the best option), but if you have a dependency on a specific Node.js version then the following will work: "npm install npm -g". 以前的答案将用于安装新版本的Node.js(可能是最佳选项),但如果您对特定的Node.js版本有依赖性,那么以下内容将起作用:“npm install npm -g”。 Verify by running npm -v before and after the command. 通过在命令之前和之后运行npm -v进行验证。

在此输入图像描述


#4楼

I followed @josh3737 and installed the latest MSI from the node.js homepage. 我关注@ josh3737并从node.js主页安装了最新的MSI。

But I had the additional problem that I still had the old node and npm on the command line. 但是我还有另一个问题,那就是命令行上仍然有旧节点和npm。 The problem was caused by the new installation, that it was installed into 问题是由安装它的新安装引起的

C:\Program Files (x86)\nodejs\

instead of the previous installation in 而不是以前的安装

C:\Program Files\nodejs\

The new installation added the new directory into my path variable after the old one. 新安装在旧路径变量之后将新目录添加到路径变量中。 So the old installation was still the active one in the path. 因此,旧安装仍然是路径中的活动安装。 After removing C:\\Program Files\\nodejs\\ from system path and C:\\Users\\...\\AppData\\Roaming\\npm from user path and restarting the command line the new installation was active. 系统路径中删除C:\\Program Files\\nodejs\\ ,从用户路径中删除C:\\Program Files\\nodejs\\ C:\\Users\\...\\AppData\\Roaming\\npm并重新启动命令行,新安装处于活动状态。

Maybe the least path was a local problem that has nothing to do with the new installation, I had two links to AppData\\Roaming\\npm in it. 也许最小的路径是与新安装无关的本地问题,我有两个指向AppData\\Roaming\\npm链接。 And maybe this can also be fixed by first uninstalling node.js and installing the new version afterwards. 也许这也可以通过首先卸载node.js并在之后安装新版本来解决。


#5楼

For what it's worth, I had to combine several answers... 对于它的价值,我必须结合几个答案......

  1. Uninstall Node.js in control panel Add/remove programs . 在控制面板中卸载Node.js 添加/删除程序
  2. Delete directories, both C:\\Program Files (x86)\\nodejs\\ and C:\\Program Files\\nodejs\\ if they exist. 删除目录,包括C:\\Program Files (x86)\\nodejs\\C:\\Program Files\\nodejs\\如果存在)。
  3. Install the latest version, http://nodejs.org/download/ 安装最新版本, http://nodejs.org/download/

#6楼

You can use Chocolatey which is a package manager for windows (like apt-get for Debian Linux). 你可以使用Chocolatey作为windows的包管理器(比如Debian Linux的apt-get)。

Install fresh (you might need to uninstall previously installed versions) 安装新鲜(您可能需要卸载以前安装的版本)

> choco install nodejs

Update to the latest version 更新到最新版本

> choco update nodejs

and for npm 并为npm

> choco update npm
发布了0 篇原创文章 · 获赞 52 · 访问量 35万+

猜你喜欢

转载自blog.csdn.net/CHCH998/article/details/105614218