When I install node 0.10.33 from the msi ( http://nodejs.org/download/ ), I get an old version of npm (1.4.28). How can I upgrade npm on Windows?
当我从msi (http://nodejs.org/download/)安装节点0.10.33时,我得到了一个旧版本的npm(1.4.28)。如何在Windows上升级npm ?
npm install -g npm
npm安装- g npm
does not work; I still have the old npm.
不工作;我还有老的npm。
9 个解决方案
#1
142
You need to follow the Windows upgrade instructions ( https://github.com/npm/npm/wiki/Troubleshooting#upgrading-on-windows )
您需要按照Windows的升级说明(https://github.com/npm/npm/npm/wiki/troubleshooting # upgradon - Windows)
tl;dr - npm -g install npm
does work, but the old version of npm is still in your PATH.
tl; npm -g安装npm确实有用,但是npm的旧版本仍然在您的路径中。
To fix this, do one of these:
要解决这个问题,请做以下其中一个:
Option 2: remove both of
选项2:删除两个。
C:\Program Files (x86)\nodejs\npm
C:\Program Files (x86)\nodejs\npm
C:\Program Files (x86)\nodejs\npm.cmd
C:\Program Files (x86)\nodejs\npm.cmd
Or
或
Option 3: Open cmd.exe as administrator, navigate to C:\Program Files (x86)\nodejs and then run the installation without -g:
选项3:打开cmd。exe作为管理员,导航到c:)程序文件(即x86),然后在没有-g的情况下运行安装:
npm install npm@latest
npm安装npm@latest
#2
42
We at Microsoft Open Source wrote a small tool to automate the process outlined above. You can find it here or just install and run it by executing the following in an elevated command prompt / PowerShell:
我们在微软开源软件上写了一个小工具来自动化上面概述的过程。您可以在这里找到它,也可以通过在命令提示符/ PowerShell中执行以下命令来安装和运行它:
npm install -g npm-windows-upgrade
npm-windows-upgrade
#3
14
There May be many ways to update your npm
in Windows
可能有很多方法可以在Windows中更新npm。
Way 1
方法1
- Open you power shell as Administrator and run following commands step by step.
- 打开power shell作为管理员,一步一步地运行以下命令。
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
- Set-ExecutionPolicy不受限制的-范围CurrentUser -Force。
npm install -g npm-windows-upgrade
- npm安装- g npm-windows-upgrade
npm-windows-upgrade
- npm-windows-upgrade
- Here you can select your preferred version of npm
- 在这里您可以选择您喜欢的npm版本。
- Ready to go !
- 准备好了!
Way 2
方法2
- You can simply upgrade to the latest
npm
version with following command - 您可以使用以下命令简单地升级到最新的npm版本。
npm install npm@latest -g
- npm安装npm@latest - g
- or if you want a specific version of
npm
simply run - 或者,如果您想要一个特定版本的npm,只需运行。
-
npm install npm@{version} -g
for examplenpm install npm@3.3.12 -g
- npm安装npm@{version} -g,例如npm安装npm@3.3.12 -g。
Now simply run npm --version
or npm -v
to know your current version of npm
现在简单地运行npm——版本或npm -v来了解当前版本的npm。
3.3.12
is my preferred version ofnpm
that best suits for approximately every package.3.3.12是我最喜欢的npm版本,它适用于几乎所有的包装。
#4
6
So, TL;DR; this worked:
所以,TL,博士;这工作:
-
Uninstall node
卸载节点
-
From a command prompt, run
where npm
从命令提示符,运行在npm的地方。
- If you had npm installed via chocolatey, you'll see a path like C:\ProgramData\chocolatey\bin\npm.exe - DELETE it!
- 如果你的npm是通过chocolatey安装的,你会看到一条像C:\ProgramData\chocolatey\bin\npm的路径。exe -删除它!
- Now install NodeJS using the appropriate MSI from https://nodejs.org/en/download/
- 现在,使用来自https://nodejs.org/en/download/的适当的MSI安装NodeJS。
- In your favourite shell, type
npm --version
- this should now echo the version of NPM that came with NodeJS (at the time of this writing, that version is 3.10.10) - 在您最喜欢的shell中,类型npm——版本——现在应该与NodeJS中出现的npm版本相呼应(在撰写本文时,该版本为3.10.10)。
This is what worked for me (goofy me!) I had (age ago) installed npm via chocolatey, which created a chocolatey initiated npm.exe in C:\ProgramData\chocolatey\bin\npm.exe. This was npm version 1.4.9 and wouldn't update no matter what one did including uninstall and reinstall NodeJs.
这就是我的工作(傻瓜我!)我是在(上个世纪前)通过巧克力来安装npm的,它创建了一个由巧克力开始的npm。exe在C:\ ProgramData \巧克力色\ bin \ npm.exe。这是npm版本1.4.9,无论你做了什么,都不会更新,包括卸载和重新安装NodeJs。
=======
= = = = = = =
EDIT: Better way to install node and npm
As of today (27/06/2017), the best way to install and manage node and npm is to install nvm (Node Version Manager) as explained here: https://github.com/coreybutler/nvm-windows. Once you have nvm, installing any node version is super easy:
截止到今天(27/06/2017),安装和管理节点和npm的最佳方法是安装nvm(节点版本管理器),如下所示:https://github.com/coreybutler/nvm-windows。一旦有了nvm,安装任何节点版本都非常简单:
- Open your favourite console (CMD, Cmder, PowerShell)
- 打开您最喜欢的控制台(CMD, Cmder, PowerShell)
- Type
nvm install 6.10.2
(to install node version 6.10.2) - 类型nvm安装6.10.2(安装节点版本6.10.2)
- To see the currently active version, type
nvm list
. This prints something like below: - 要查看当前活动的版本,请键入nvm列表。这是如下图所示:
6.9.3
* 6.9.2 (Currently using 64-bit executable)
6.9.1
6.10.2
#5
0
I did something similar to Sam Mikes. I'm only sharing this because I couldn't get either of his solutions to work on my rig. After a bit of playing around, this is what worked for me:
我做了类似Sam Mikes的事。我只是分享这些,因为我无法得到他的任何一个解决方案。在玩了一会儿之后,这就是我的工作:
- Remove NPM/Node from your Environment Variables, both for user and system.
- 从环境变量中删除NPM/节点,用于用户和系统。
- Close your open console if you have one open, then open a console as administrator
- 如果您有一个打开的控制台,请关闭您的开放控制台,然后作为管理员打开控制台。
- Change directories to
%USERPROFILE%
-- that's a window's environment variable that takes you toC:\Users\CurrentlyLoggedInUser
- 更改目录% USERPROFILE %——这是一个窗口的环境变量,需要你C:\Users\ CurrentlyLoggedInUser
- Run from the console in %USERPROFILE%,
"C:\Program Files\nodejs\npm" install npm -g
(you might have yours in the x86 folder) - 在%USERPROFILE%的控制台运行,“C:\程序文件\nodejs\npm”安装npm -g(您可能在x86文件夹中有您的)
- If this solution would work for you, step 4 would have worked, and
npm -v
will show a an up-to-date version - 如果这个解决方案对您有效,那么步骤4将会成功,而npm -v将显示一个最新版本。
- Re-add Node (in Program Files)/NPM (in App Data -- the one installed in Program Files should be the old one) to your user and system environment variables
- 重新添加节点(在程序文件中)/NPM(在应用程序数据中——在程序文件中安装的应该是旧的)到您的用户和系统环境变量。
Note: I've used the Microsoft automated script in the past to fix this, but only because I didn't realize how easy it would be to do it myself.
注意:我在过去使用过Microsoft自动化脚本来修复这个问题,但只是因为我没有意识到自己做这件事是多么容易。
#6
0
So none of the previous answers solved the issue for me so I thought I would post my specific solution, which I managed to figure out by going through all the other answers so they were really helpful.
所以之前的回答都没有解决这个问题,所以我想我应该发布我的具体解决方案,我通过所有其他的答案来解决这个问题,所以它们真的很有帮助。
My issue was because I had used chocolatey to install node and possibly npm (looking at chocolatey site now I shouldn't have done that).
我的问题是,我用了巧克力来安装node,可能是npm(现在我不应该去看巧克力网站了)。
To solve the issue I simply had to run the relevant choco uninstall commands for npm and node and then everything switched to the other version of node which I had also installed using the node msi (from node's website).
为了解决这个问题,我只需要为npm和节点运行相关的choco卸载命令,然后所有的东西都切换到另一个版本的节点,我也使用node msi(从node的网站)安装了这个版本。
I hope that helps anyone else that may have gone down the same path as me.
我希望这能帮助那些和我走在同一条道路上的人。
#7
0
Use npm-windows-upgrade tool to simply upgrade. Steps are provided in the link.
使用npm-windows升级工具简单地升级。步骤在链接中提供。
#8
0
I tried almost every answer but none of them works my way.
Neither npm-windows-upgrade worked nor did the npm install npm@latest etc etc worked.
For people like me I will suggest you guys downloading the latest installer from Node.js website, let the existing version of node directory be on it's place and without changing anything just install the msi installer and you will end up with an upgraded version of node.
My case was upgrading node from 6 to 8.9.3
我试了几乎所有的答案,但没有一个能按我的方式。npm-windows-升级工作都没有成功,npm也没有安装npm@latest等。对于像我这样的人,我建议你们从Node下载最新的安装程序。js网站,让现有版本的节点目录在它的位置上,而不改变任何东西,只要安装msi安装程序,你就会得到一个升级版的节点。我的案例是从6升级到8.9.3。
#9
-4
For update node npm on Windows
用于Windows上的更新节点npm。
I have to delete node in:
我必须删除节点:
C:\Users**YOUR USER**\AppData\Roaming
C:\用户* *用户* * \ AppData \漫游
And reinstall node
和重新安装节点
#1
142
You need to follow the Windows upgrade instructions ( https://github.com/npm/npm/wiki/Troubleshooting#upgrading-on-windows )
您需要按照Windows的升级说明(https://github.com/npm/npm/npm/wiki/troubleshooting # upgradon - Windows)
tl;dr - npm -g install npm
does work, but the old version of npm is still in your PATH.
tl; npm -g安装npm确实有用,但是npm的旧版本仍然在您的路径中。
To fix this, do one of these:
要解决这个问题,请做以下其中一个:
Option 2: remove both of
选项2:删除两个。
C:\Program Files (x86)\nodejs\npm
C:\Program Files (x86)\nodejs\npm
C:\Program Files (x86)\nodejs\npm.cmd
C:\Program Files (x86)\nodejs\npm.cmd
Or
或
Option 3: Open cmd.exe as administrator, navigate to C:\Program Files (x86)\nodejs and then run the installation without -g:
选项3:打开cmd。exe作为管理员,导航到c:)程序文件(即x86),然后在没有-g的情况下运行安装:
npm install npm@latest
npm安装npm@latest
#2
42
We at Microsoft Open Source wrote a small tool to automate the process outlined above. You can find it here or just install and run it by executing the following in an elevated command prompt / PowerShell:
我们在微软开源软件上写了一个小工具来自动化上面概述的过程。您可以在这里找到它,也可以通过在命令提示符/ PowerShell中执行以下命令来安装和运行它:
npm install -g npm-windows-upgrade
npm-windows-upgrade
#3
14
There May be many ways to update your npm
in Windows
可能有很多方法可以在Windows中更新npm。
Way 1
方法1
- Open you power shell as Administrator and run following commands step by step.
- 打开power shell作为管理员,一步一步地运行以下命令。
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
- Set-ExecutionPolicy不受限制的-范围CurrentUser -Force。
npm install -g npm-windows-upgrade
- npm安装- g npm-windows-upgrade
npm-windows-upgrade
- npm-windows-upgrade
- Here you can select your preferred version of npm
- 在这里您可以选择您喜欢的npm版本。
- Ready to go !
- 准备好了!
Way 2
方法2
- You can simply upgrade to the latest
npm
version with following command - 您可以使用以下命令简单地升级到最新的npm版本。
npm install npm@latest -g
- npm安装npm@latest - g
- or if you want a specific version of
npm
simply run - 或者,如果您想要一个特定版本的npm,只需运行。
-
npm install npm@{version} -g
for examplenpm install npm@3.3.12 -g
- npm安装npm@{version} -g,例如npm安装npm@3.3.12 -g。
Now simply run npm --version
or npm -v
to know your current version of npm
现在简单地运行npm——版本或npm -v来了解当前版本的npm。
3.3.12
is my preferred version ofnpm
that best suits for approximately every package.3.3.12是我最喜欢的npm版本,它适用于几乎所有的包装。
#4
6
So, TL;DR; this worked:
所以,TL,博士;这工作:
-
Uninstall node
卸载节点
-
From a command prompt, run
where npm
从命令提示符,运行在npm的地方。
- If you had npm installed via chocolatey, you'll see a path like C:\ProgramData\chocolatey\bin\npm.exe - DELETE it!
- 如果你的npm是通过chocolatey安装的,你会看到一条像C:\ProgramData\chocolatey\bin\npm的路径。exe -删除它!
- Now install NodeJS using the appropriate MSI from https://nodejs.org/en/download/
- 现在,使用来自https://nodejs.org/en/download/的适当的MSI安装NodeJS。
- In your favourite shell, type
npm --version
- this should now echo the version of NPM that came with NodeJS (at the time of this writing, that version is 3.10.10) - 在您最喜欢的shell中,类型npm——版本——现在应该与NodeJS中出现的npm版本相呼应(在撰写本文时,该版本为3.10.10)。
This is what worked for me (goofy me!) I had (age ago) installed npm via chocolatey, which created a chocolatey initiated npm.exe in C:\ProgramData\chocolatey\bin\npm.exe. This was npm version 1.4.9 and wouldn't update no matter what one did including uninstall and reinstall NodeJs.
这就是我的工作(傻瓜我!)我是在(上个世纪前)通过巧克力来安装npm的,它创建了一个由巧克力开始的npm。exe在C:\ ProgramData \巧克力色\ bin \ npm.exe。这是npm版本1.4.9,无论你做了什么,都不会更新,包括卸载和重新安装NodeJs。
=======
= = = = = = =
EDIT: Better way to install node and npm
As of today (27/06/2017), the best way to install and manage node and npm is to install nvm (Node Version Manager) as explained here: https://github.com/coreybutler/nvm-windows. Once you have nvm, installing any node version is super easy:
截止到今天(27/06/2017),安装和管理节点和npm的最佳方法是安装nvm(节点版本管理器),如下所示:https://github.com/coreybutler/nvm-windows。一旦有了nvm,安装任何节点版本都非常简单:
- Open your favourite console (CMD, Cmder, PowerShell)
- 打开您最喜欢的控制台(CMD, Cmder, PowerShell)
- Type
nvm install 6.10.2
(to install node version 6.10.2) - 类型nvm安装6.10.2(安装节点版本6.10.2)
- To see the currently active version, type
nvm list
. This prints something like below: - 要查看当前活动的版本,请键入nvm列表。这是如下图所示:
6.9.3
* 6.9.2 (Currently using 64-bit executable)
6.9.1
6.10.2
#5
0
I did something similar to Sam Mikes. I'm only sharing this because I couldn't get either of his solutions to work on my rig. After a bit of playing around, this is what worked for me:
我做了类似Sam Mikes的事。我只是分享这些,因为我无法得到他的任何一个解决方案。在玩了一会儿之后,这就是我的工作:
- Remove NPM/Node from your Environment Variables, both for user and system.
- 从环境变量中删除NPM/节点,用于用户和系统。
- Close your open console if you have one open, then open a console as administrator
- 如果您有一个打开的控制台,请关闭您的开放控制台,然后作为管理员打开控制台。
- Change directories to
%USERPROFILE%
-- that's a window's environment variable that takes you toC:\Users\CurrentlyLoggedInUser
- 更改目录% USERPROFILE %——这是一个窗口的环境变量,需要你C:\Users\ CurrentlyLoggedInUser
- Run from the console in %USERPROFILE%,
"C:\Program Files\nodejs\npm" install npm -g
(you might have yours in the x86 folder) - 在%USERPROFILE%的控制台运行,“C:\程序文件\nodejs\npm”安装npm -g(您可能在x86文件夹中有您的)
- If this solution would work for you, step 4 would have worked, and
npm -v
will show a an up-to-date version - 如果这个解决方案对您有效,那么步骤4将会成功,而npm -v将显示一个最新版本。
- Re-add Node (in Program Files)/NPM (in App Data -- the one installed in Program Files should be the old one) to your user and system environment variables
- 重新添加节点(在程序文件中)/NPM(在应用程序数据中——在程序文件中安装的应该是旧的)到您的用户和系统环境变量。
Note: I've used the Microsoft automated script in the past to fix this, but only because I didn't realize how easy it would be to do it myself.
注意:我在过去使用过Microsoft自动化脚本来修复这个问题,但只是因为我没有意识到自己做这件事是多么容易。
#6
0
So none of the previous answers solved the issue for me so I thought I would post my specific solution, which I managed to figure out by going through all the other answers so they were really helpful.
所以之前的回答都没有解决这个问题,所以我想我应该发布我的具体解决方案,我通过所有其他的答案来解决这个问题,所以它们真的很有帮助。
My issue was because I had used chocolatey to install node and possibly npm (looking at chocolatey site now I shouldn't have done that).
我的问题是,我用了巧克力来安装node,可能是npm(现在我不应该去看巧克力网站了)。
To solve the issue I simply had to run the relevant choco uninstall commands for npm and node and then everything switched to the other version of node which I had also installed using the node msi (from node's website).
为了解决这个问题,我只需要为npm和节点运行相关的choco卸载命令,然后所有的东西都切换到另一个版本的节点,我也使用node msi(从node的网站)安装了这个版本。
I hope that helps anyone else that may have gone down the same path as me.
我希望这能帮助那些和我走在同一条道路上的人。
#7
0
Use npm-windows-upgrade tool to simply upgrade. Steps are provided in the link.
使用npm-windows升级工具简单地升级。步骤在链接中提供。
#8
0
I tried almost every answer but none of them works my way.
Neither npm-windows-upgrade worked nor did the npm install npm@latest etc etc worked.
For people like me I will suggest you guys downloading the latest installer from Node.js website, let the existing version of node directory be on it's place and without changing anything just install the msi installer and you will end up with an upgraded version of node.
My case was upgrading node from 6 to 8.9.3
我试了几乎所有的答案,但没有一个能按我的方式。npm-windows-升级工作都没有成功,npm也没有安装npm@latest等。对于像我这样的人,我建议你们从Node下载最新的安装程序。js网站,让现有版本的节点目录在它的位置上,而不改变任何东西,只要安装msi安装程序,你就会得到一个升级版的节点。我的案例是从6升级到8.9.3。
#9
-4
For update node npm on Windows
用于Windows上的更新节点npm。
I have to delete node in:
我必须删除节点:
C:\Users**YOUR USER**\AppData\Roaming
C:\用户* *用户* * \ AppData \漫游
And reinstall node
和重新安装节点