如何在Windows上更新npm ?

时间:2021-04-26 07:27:48

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上做这个?

29 个解决方案

#1


1125  

This is the new best way to upgrade npm on Windows.

这是在Windows上升级npm的新方法。

Run PowerShell as Administrator

以管理员身份运行PowerShell

Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
npm install -g npm-windows-upgrade
npm-windows-upgrade

Note: Do not run npm i -g npm. Instead use npm-windows-upgrade to update npm going forward. Also if you run the NodeJS installer, it will replace the node version.

注意:不要运行npm i -g npm。相反,使用npm- windowsupgrade来更新npm。同样,如果运行NodeJS安装程序,它将替换节点版本。

  • Upgrades npm in-place, where node installed it.
  • 升级npm就地,在那里节点安装它。
  • Easy updating, update to the latest by running npm-windows-upgrade -p -v latest.
  • 易于更新,更新到最新的运行npm-windows-升级-p -v最新。
  • Does not modify the default path.
  • 不修改默认路径。
  • Does not change the default global package location.
  • 不更改默认的全局包位置。
  • Allows easy upgrades and downgrades.
  • 允许简单的升级和降级。
  • Officially recommended by the NPM team.
  • 由NPM团队正式推荐。
  • A list of versions matched between NPM and NODE (https://nodejs.org/en/download/releases/) - but you will need to download NODE INSTALLER and run that to update node (https://nodejs.org/en/)
  • 在NPM和节点之间匹配的版本列表(https://nodejs.org/en/download/releases/)——但是您需要下载节点安装程序并运行它来更新节点(https://nodejs.org/en/)

#2


465  

Download and run the latest MSI. The MSI will update your installed node and npm.

下载并运行最新的MSI。MSI将更新已安装的节点和npm。

#3


91  

To update NPM, this worked for me:

为了更新NPM,这对我起了作用:

  • Navigate in your shell to your node installation directory, eg C:\Program Files (x86)\nodejs
  • 导航节点安装目录在您的shell,如C:\Program Files (x86)\nodejs
  • run npm install npm (no -g option)
  • 运行npm安装npm (no -g选项)

#4


45  

You can use Chocolatey which is a package manager for windows (like apt-get for Debian Linux).

您可以使用一个用于windows的包管理器(比如Debian Linux的apt-get)。

Install fresh (you might need to uninstall previously installed versions)

安装fresh(可能需要卸载之前安装的版本)

> choco install nodejs

Update to the latest version

更新到最新版本。

> choco update nodejs

and for npm

和npm

> choco update npm

#5


44  

Like some people, I needed to combine multiple answers, and I also needed to set a proxy.

像有些人一样,我需要组合多个答案,我还需要设置一个代理。

This should work for anyone. I have zero desire to run an EXE file or MSI file .. uninstall/ reinstall, or manually delete files and folders. That is so 1999 :P

这对任何人都适用。我不想运行EXE文件或MSI文件。卸载/重新安装,或手动删除文件和文件夹。那是1999年的事了。

  1. Run this to update NPM:

    运行这个更新NPM:

    Run PowerShell as administrator

    以管理员身份运行PowerShell

    npm i -g npm    // This works
    

    I am not thinking this code actually upgrades your npm version below

    我不认为这段代码实际上是在升级你的npm版本。

    Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
    npm install -g npm-windows-upgrade
    npm-windows-upgrade
    
    (courtesy of "Robert" answer)
    

Run this to update Node.js:

运行这个来更新Node.js:

wget https://nodejs.org/download/release/latest/win-x64/node.exe -OutFile 'C:\Program Files (x86)\nodejs\node.exe'    (courtesy of BrunoLM answer)

If you get `wget : Could not find a part of the path .... "**, see below ...scroll down. Reading Web Response... It's at least punching through the firewall /proxy (if you have one or have already ran the code get through ...

如果你得到的wget:找不到路径的一部分....“* *,见下文…向下滚动。阅读网络响应……它至少可以通过防火墙/代理(如果您有一个或已经运行过代码的话)。

Otherwise

否则

You might need to set your proxy

您可能需要设置代理。

npm config set proxy "http://proxy.yourcorp.com:811"    (yes, use quotes)

2 possible errors

2可能的错误

  1. It cannot find path of the path solution "where.exe node" (courtesy of Lonnie Best Answer)

    它找不到路径解的路径。exe节点(由Lonnie Best Answer提供)

    E.g. if Node.js is NOT living in "Program Files (x86)" perhaps with where.exe, it is living in 'C:\Program Files\nodejs\node.exe'.

    例如,如果节点。js并不是生活在“程序文件(x86)”中。exe,它住在“C:\程序文件\nodejs\node.exe”。

    wget https://nodejs.org/download/release/latest/win-x64/node.exe -OutFile 'C:\Program Files\nodejs\node.exe'
    
  2. Now perhaps it tries to upgrade but you get another error, "node.exe is being used by another process."

    也许它试图升级,但你会得到另一个错误,"node。exe正在被另一个进程使用。

    • Close /shutdown other consoles .. command prompts and PowerShell windows, etc. Even if you're using npm in a command prompt, close it.
    • 关闭/关闭其他控制台。命令提示和PowerShell窗口等。即使您在命令提示符中使用npm,关闭它。

npm -v (3.10.8)

npm - v(3.10.8)

node -v ( v6.6.0)

节点- v(v6.6.0)

DONE. I'm at the version that I want.

完成了。我想要的版本。

#6


21  

You can update your npm to the latest stable version with the following command:

您可以使用以下命令将您的npm更新为最新的稳定版本:

 npm install npm@latest -g

Use PowerShell to run it. This command doesn't need windows administrator privileges and you can verify the result with npm -v

使用PowerShell来运行它。这个命令不需要windows管理员权限,您可以通过npm -v验证结果。

#7


18  

This works fine for me to update npm on Windows 7 x64:

这对我来说适用于Windows 7 x64上的npm更新:

  • Windows start
  • 启动Windows
  • All Programs
  • 所有程序
  • Node.js
  • node . js
  • Node.js command prompt (alternative click)
  • 节点。js命令提示符(alternative click)
  • Run as administrator

    以管理员身份运行

    $ npm -g install npm

    $ npm -g安装npm。

  • remove C:\Program Files\nodejs\npm.cmd the new npm will be at C:\Users\username\appdata\roaming\npm\npm.cmd

    删除C:\Program Files\nodejs\npm.在C:\Users\username\appdata\roaming\npm\npm.cmd cmd新npm将

Hope this helps.

希望这个有帮助。

#8


14  

Open PowerShell as administrator.

开放PowerShell管理员。

To install a first time you can use this small script to download the latest msi and run it

要安装第一次,您可以使用这个小脚本下载最新的msi并运行它。

$nodeLatest=((curl https://nodejs.org/download/release/latest/).Content | findstr x64.msi) -replace "<(.*?)>", "" -replace "\s+.+", "";
wget "https://nodejs.org/download/release/latest/$nodeLatest" -OutFile (join-path $env:TEMP node.msi); Start-Process (join-path $env:TEMP node.msi)

On future upgrades you can download just node.exe and update npm with

在以后的升级中,您可以下载节点。执行和更新npm。

wget https://nodejs.org/download/release/latest/win-x64/node.exe -OutFile 'C:\Program Files\nodejs\node.exe'
npm i -g npm

You should now have the latest node and npm.

您现在应该拥有最新的节点和npm。


I went a little further and decided to implement a nvm for Windows.

我更进一步,决定为Windows实现一个nvm。

https://github.com/brunolm/nvm

https://github.com/brunolm/nvm

Install-Module -Name power-nvm

nvm install latest
nvm default latest

#9


13  

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". Verify by running npm -v before and after the command.

前面的答案将用于安装新版本的节点。js(可能是最好的选择),但是如果您对某个特定节点有依赖关系。js版本接下来的工作是:“npm安装npm -g”。在命令之前和之后运行npm -v验证。

如何在Windows上更新npm ?

#10


10  

Use Upgrade npm on Windows

在Windows上使用升级npm。

This is the official document for a user to upgrade npm on Windows!

这是用户在Windows上升级npm的官方文件!

Here is my screenshot!

这是我的截图!

如何在Windows上更新npm ?

#11


7  

How to Update Node.js:

  1. Uninstall Node.js. Click the Start menu, type "Change or Remove a Program", click on the item shown, find Node.js in the list and uninstall it.

    卸载node . js。单击“开始”菜单,键入“更改或删除一个程序”,单击显示的项,查找节点。在列表中的js并卸载它。

  2. Delete directories, both C:\Program Files (x86)\nodejs\ and C:\Program Files\nodejs\ if they exist.

    如果存在的话,删除目录,包括c:)的程序文件(文件)、x86nodejs\和c:)。

  3. Install the latest, https://nodejs.org/en/download

    安装最新的,https://nodejs.org/en/download

    The uninstall/delete/install seems unnecessary, but it often is and this will save your time.     These instructions come from Microsoft.

卸载/删除/安装似乎是不必要的,但它经常是,这将节省您的时间。这些指令来自微软。

How to Update NPM:

    https://www.npmjs.com/package/npm-windows-upgrade

https://www.npmjs.com/package/npm-windows-upgrade

    This is the official documentation for upgrading npm on windows.

这是在windows上升级npm的官方文件。

All was tested and working on Windows 10 (2017).

所有测试都在Windows 10(2017)上进行测试。

#12


6  

For what it's worth, I had to combine several answers...

为了它的价值,我必须结合几个答案……

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

#13


4  

For me, after totally uninstalling node. 10.29, and then installing node 4.2.2, there remained a 10.29 node.exe file in my c:\windows folder.

对我来说,完全卸载节点之后。10.29,然后安装节点4.2.2,仍然有一个10.29节点。exe文件在我的c:\windows文件夹。

I found this by using the following command:

我通过以下命令找到了这个:

where.exe node

The command returned:

返回的命令:

C:\Windows\node.exe
C:\Program Files\nodejs\node.exe

So even though I had successfully installed version 4.2.2 via the msi executable, the command "node -v" would continue to return 10.29.

因此,即使我通过msi可执行文件成功安装了4.2.2版本,命令“node -v”仍将返回10.29。

I resolved this by deleting this file:

我通过删除这个文件解决了这个问题:

C:\Windows\node.exe

#14


3  

I followed @josh3737 and installed the latest MSI from the node.js homepage.

我遵循@josh3737,并从节点安装了最新的MSI。js主页。

But I had the additional problem that I still had the old node and npm on the command line. The problem was caused by the new installation, that it was installed into

但是我还有一个额外的问题,那就是在命令行上仍然有老节点和npm。这个问题是由于安装新装置引起的。

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.

新的安装程序将新目录添加到我的path变量中。所以旧的安装仍然是在路上的活动。从系统删除C:\Program Files\nodejs\后路径和C:\Users\...\AppData\从用户路径到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. And maybe this can also be fixed by first uninstalling node.js and installing the new version afterwards.

也许最小的路径是一个本地问题,与新安装无关,我有两个AppData\ npm的链接。也许这也可以通过第一个卸载节点来修复。然后再安装新版本。

#15


3  

I was also facing similar issues. I followed below mentioned steps and it worked for me:

我也面临着同样的问题。我遵循以下步骤,它为我工作:

  • go to Windows > Start > Node.js

    到Windows >启动> Node.js。

    • right click on Node.js command prompt
    • 右键单击节点。js命令提示符
    • click on Run as administrator
    • 单击Run作为管理员。
  • ping registry.npmjs.org

    ping registry.npmjs.org

  • npm view npm version

    npm视图npm版本

  • cd %ProgramFiles%\nodejs

    cd % ProgramFiles % \ nodejs

  • npm install npm@latest

    npm安装npm@latest

and npm updated successfully. Earlier I was trying for CMD and that was throwing error. may be some path issue that got resolved by running NodeJs Command Prompt. hope it'll work for you. try this.

和npm成功更新。早些时候,我在尝试CMD,那是抛出错误。可能是某个路径问题,通过运行NodeJs命令提示符得到解决。希望它对你有用。试试这个。

#16


3  

this is best tool to maintain version of NODE.Js i NVM

这是维护NODE版本的最佳工具。Js我NVM

Node Version Manager (nvm) for Windows but for Windows, with an installer. Download Now! This has always been a node version manager, not an io.js manager, so there is no back-support for io.js. However, node 4+ is supported. 如何在Windows上更新npm ?

用于Windows的节点版本管理器(nvm),但适用于Windows的安装程序。现在下载!这一直是一个节点版本管理器,而不是io。js经理,所以没有对io.j的支持。但是,支持节点4+。

#17


2  

OK guys, I read (tried on Windows) all the previous stuff and all of these answers have their own disadvantages.

好了,我读过(在Windows上试过)之前所有的东西,所有这些答案都有自己的缺点。

For the best way to update Node.js (at least for me), go to https://nodejs.org/en/ Then download the last version and install it in same folder you installed the previous version in - 1 min and it's done. You don't need to remove any old files.

为更新节点的最佳方式。js(至少对我来说),到https://nodejs.org/en/然后下载最后一个版本,并将其安装到你安装之前版本的相同文件夹中——1分钟,完成了。您不需要删除任何旧文件。

Then update npm typing in cmd: npm install --save latest-version

然后在cmd中更新npm类型:npm安装——保存最新版本。

#18


2  

To install the updates, just download the installer from the Nodejs.org site and run it again. The new version of Node.js and NPM will replace the older versions.

要安装更新,只需从Nodejs.org站点下载安装程序并再次运行它。新版本的节点。js和NPM将取代旧版本。

#19


1  

This works fine for me

这对我来说没问题。

  1. Run Command Prompt as Administrator

    作为管理员运行命令提示符。

  2. Navigate to the folder containing nodejs (eg. C:\Program Files\nodejs)
  3. 导航到包含nodejs的文件夹(如。C:\Program Files\ nodejs)
  4. Run Powershell -ExecutionPolicy Unrestricted

    运行Powershell -ExecutionPolicy无限制的

  5. Run npm-windows-upgrade

    运行npm-windows-upgrade

  6. This will show list of versions available to install. Just select your desired version by moving up/down key & Press Enter.

    This'll update your npm
  7. 这将显示可用于安装的版本列表。选择你想要的版本,通过向上/向下键和按回车。这将更新你的npm
  8. To check the current version of npm

    Run npm --version

    运行npm——版本

Command Prompt Screenshot

命令提示符截图

#20


1  

follow these steps for window 10 or window 8

按照下面的步骤操作10或8窗口。

  • press WIN + R and type cmd and enter
  • 按WIN + R和type cmd并输入。
  • npm i -g npm@next
  • npm我- g npm@next
  • npm i -g npm@next OR npm i -g node@{version}
  • npm i -g npm@next或npm i -g node@{version}
  • Remove environment path C:\Program Files\nodejs from envrionment variable PATH.
  • 删除环境路径C:\Program Files\nodejs从环境变量路径。
  • type refreshenv in cmd
  • 类型refreshenv cmd

Now you will have your new version which you installed.

现在您将拥有您安装的新版本。

Note: If you don't remove path. You will see the previous version of node.

注意:如果您不删除路径。您将看到以前版本的节点。

#21


0  

You can use these commands:

您可以使用以下命令:

npm cache clean
npm update -g [package....]

If you are upgrading from a previous version of node, then you will want to update all existing global packages. You can also specify the package name to be updated.

如果您正在从先前版本的节点升级,那么您将需要更新所有现有的全局包。您还可以指定要更新的包名称。

#22


0  

This might help someone. Neither "npm-windows-upgrade" nor the installer alone did it for me. Powershell was still using an older version of node and npm.

这可能会帮助别人。无论是“npm- windowsupgrade”还是安装程序都没有为我做。Powershell仍然使用老版本的节点和npm。

So this is what I did (worked for me): 1. Download the latest installer from nodejs.org. Install node. It will update your node; everywhere (Powershell, cmd etc.). 2. Install the npm-windows-upgrade package (npm install -g npm-windows-upgrade) and run npm-windows-upgrade.

这就是我所做的(为我工作):1。从nodejs.org下载最新的安装程序。安装节点。它将更新您的节点;到处(Powershell cmd等)。2。安装npm-windows升级包(npm安装- gnpm - windowsupgrade)并运行npm- windowsupgrade。

I didn't uninstall anything and didn't set any paths.

我没有卸载任何东西,也没有设置任何路径。

#23


0  

In my case, I discovered that I had two copies of Node.js installed. One under "C:\Program Files\nodejs" and another under "C:\Program Files (x86)\nodejs".

在我的例子中,我发现我有两个节点副本。js安装。一个在“C:\程序文件\nodejs”下,另一个在“C:\程序文件(x86)\nodejs”下。

#24


0  

The easiest way I found so far to update Node.js is using Chocolatey. Use Chocolatey to install or update the latest version of Node.js on Windows:

到目前为止我发现的最简单的更新节点的方法。js使用巧克力色。使用Chocolatey来安装或更新最新版本的节点。js在Windows上:

Step 1: First, ensure that you already have Chocolatey installed. If not, use an administrative shell to install chocolatey through cmd.exe or PowerShell.exe. For more information, visit: https://chocolatey.org/docs/installation

步骤一:首先,确保你已经安装了巧克力。如果没有,请使用管理shell通过cmd安装巧克力。exe或PowerShell.exe。有关更多信息,请访问:https://chocolatey.org/docs/installation。

Step 2: Install with cmd.exe. Run the following command:

步骤2:使用cmd.exe安装。运行以下命令:

@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

To install with PowerShell.exe, visit: https://chocolatey.org/docs/installation

PowerShell的安装。exe,请访问:https://chocolatey.org/docs/installation

Step 3: Install or Update with following commands on cmd.exe (on administrative mode)

步骤3:在cmd上安装或更新以下命令。exe(行政模式)

To Install Node.js: cinst nodejs.install

安装节点。js:cinst nodejs.install

To Update Node.js: cup nodejs.install

更新节点。js:杯nodejs.install

#25


0  

For NodeJS

对于NodeJS

Download required node version msi from here and install

从这里下载所需的节点版本msi并安装。

for Npm

对于Npm

Run PowerShell as Administrator

以管理员身份运行PowerShell

Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
npm install -g npm-windows-upgrade
npm-windows-upgrade

#26


0  

1. Installing latest npm version

1。npm安装最新版本

npm install –g npm@latest 

(You can type "npm –version" to check that)

(你可以输入“npm -版本”来检查)


2. Installing Node

2。安装节点

a. Install node new version via following URL: https://nodejs.org/en/download/current/ Follow the default choices
b. Remove C:\Users\\AppData\Roaming\NPM
c. Remove C:\Users\\AppData\Roaming\npm-cache

。安装节点新版本通过以下URL:https://nodejs.org/en/download/current/按照默认选择b。删除C:\Users\ \ AppData \漫游\ NPM c。删除C:\Users\ \ AppData \ \ npm-cache徘徊


Optionally:

(可选):

d. (Delete node_modules folder in your current project folder)
e. npm cache verify
f. npm install

d.(删除当前项目文件夹中的node_modules文件夹)e. npm缓存验证f. npm安装。

#27


0  

To upgrade, run: npm install npm@latest -g.

升级,运行:npm安装npm@latest -g。

This will upgrade to the latest stable version. The time I wrote this answer, the stable version is 5.8.0.

这将升级到最新的稳定版本。我写这个答案的时候,稳定的版本是5.8.0。

You can also find this information in the footer section of npm docs page. https://docs.npmjs.com/getting-started/what-is-npm

您也可以在npm文档页的页脚部分找到这些信息。https://docs.npmjs.com/getting-started/what-is-npm

#28


-1  

This is what worked for me.

这就是我的工作。

  1. Open a local folder other than the one in which nodejs is installed.
  2. 打开一个本地文件夹,而不是安装nodejs的本地文件夹。
  3. Install npm in that folder with command npm install npm
  4. 在该文件夹中安装npm,命令npm安装npm。
  5. Navigate to the folder containing node js. (C:\Program Files\nodejs\node_modules)
  6. 导航到包含node js的文件夹。(C:\ Program Files \ nodejs \ node_modules)
  7. Delete the npm folder and replace it with the npm and bin folders in the local folder.
  8. 删除npm文件夹,并将其替换为本地文件夹中的npm和bin文件夹。
  9. Run npm -v. Now you would get updated version for npm.
  10. 运行npm - v。现在你会得到npm的更新版本。

Note: I tried installing npm directly in "C:\Program Files\nodejs\node_modules" but it created errors.

注意:我尝试直接在“C:\程序文件\nodejs\node_modules”中安装npm,但它造成了错误。

#29


-2  

  1. Start
  2. 开始
  3. Search for windows powershell
  4. 寻找windows powershell
  5. Right click and run as administrator
  6. 右击并作为管理员运行。
  7. Type: where.exe node (returns the path of node.exe in your system. Copy this)
  8. 类型:。exe节点(返回节点路径)。exe在您的系统。复制这个)
  9. wget https://nodejs.org/download/release/latest/win-x64/node.exe -OutFile 'PATH-OF-NODE.EXE_WHICH_YOU_COPIED_JUST_NOW'
  10. wget https://nodejs.org/download/release/latest/win-x64/node.exe输出文件“PATH-OF-NODE.EXE_WHICH_YOU_COPIED_JUST_NOW”
  11. To check if it has worked, go to your Git bash/Normal command prompt and type: node -v
  12. 要检查它是否有效,请访问Git bash/Normal命令提示符和类型:node -v。
  13. Here you can find the current version of node: https://nodejs.org/en/blog/release/
  14. 在这里您可以找到当前版本的节点:https://nodejs.org/en/blog/release/。

#1


1125  

This is the new best way to upgrade npm on Windows.

这是在Windows上升级npm的新方法。

Run PowerShell as Administrator

以管理员身份运行PowerShell

Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
npm install -g npm-windows-upgrade
npm-windows-upgrade

Note: Do not run npm i -g npm. Instead use npm-windows-upgrade to update npm going forward. Also if you run the NodeJS installer, it will replace the node version.

注意:不要运行npm i -g npm。相反,使用npm- windowsupgrade来更新npm。同样,如果运行NodeJS安装程序,它将替换节点版本。

  • Upgrades npm in-place, where node installed it.
  • 升级npm就地,在那里节点安装它。
  • Easy updating, update to the latest by running npm-windows-upgrade -p -v latest.
  • 易于更新,更新到最新的运行npm-windows-升级-p -v最新。
  • Does not modify the default path.
  • 不修改默认路径。
  • Does not change the default global package location.
  • 不更改默认的全局包位置。
  • Allows easy upgrades and downgrades.
  • 允许简单的升级和降级。
  • Officially recommended by the NPM team.
  • 由NPM团队正式推荐。
  • A list of versions matched between NPM and NODE (https://nodejs.org/en/download/releases/) - but you will need to download NODE INSTALLER and run that to update node (https://nodejs.org/en/)
  • 在NPM和节点之间匹配的版本列表(https://nodejs.org/en/download/releases/)——但是您需要下载节点安装程序并运行它来更新节点(https://nodejs.org/en/)

#2


465  

Download and run the latest MSI. The MSI will update your installed node and npm.

下载并运行最新的MSI。MSI将更新已安装的节点和npm。

#3


91  

To update NPM, this worked for me:

为了更新NPM,这对我起了作用:

  • Navigate in your shell to your node installation directory, eg C:\Program Files (x86)\nodejs
  • 导航节点安装目录在您的shell,如C:\Program Files (x86)\nodejs
  • run npm install npm (no -g option)
  • 运行npm安装npm (no -g选项)

#4


45  

You can use Chocolatey which is a package manager for windows (like apt-get for Debian Linux).

您可以使用一个用于windows的包管理器(比如Debian Linux的apt-get)。

Install fresh (you might need to uninstall previously installed versions)

安装fresh(可能需要卸载之前安装的版本)

> choco install nodejs

Update to the latest version

更新到最新版本。

> choco update nodejs

and for npm

和npm

> choco update npm

#5


44  

Like some people, I needed to combine multiple answers, and I also needed to set a proxy.

像有些人一样,我需要组合多个答案,我还需要设置一个代理。

This should work for anyone. I have zero desire to run an EXE file or MSI file .. uninstall/ reinstall, or manually delete files and folders. That is so 1999 :P

这对任何人都适用。我不想运行EXE文件或MSI文件。卸载/重新安装,或手动删除文件和文件夹。那是1999年的事了。

  1. Run this to update NPM:

    运行这个更新NPM:

    Run PowerShell as administrator

    以管理员身份运行PowerShell

    npm i -g npm    // This works
    

    I am not thinking this code actually upgrades your npm version below

    我不认为这段代码实际上是在升级你的npm版本。

    Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
    npm install -g npm-windows-upgrade
    npm-windows-upgrade
    
    (courtesy of "Robert" answer)
    

Run this to update Node.js:

运行这个来更新Node.js:

wget https://nodejs.org/download/release/latest/win-x64/node.exe -OutFile 'C:\Program Files (x86)\nodejs\node.exe'    (courtesy of BrunoLM answer)

If you get `wget : Could not find a part of the path .... "**, see below ...scroll down. Reading Web Response... It's at least punching through the firewall /proxy (if you have one or have already ran the code get through ...

如果你得到的wget:找不到路径的一部分....“* *,见下文…向下滚动。阅读网络响应……它至少可以通过防火墙/代理(如果您有一个或已经运行过代码的话)。

Otherwise

否则

You might need to set your proxy

您可能需要设置代理。

npm config set proxy "http://proxy.yourcorp.com:811"    (yes, use quotes)

2 possible errors

2可能的错误

  1. It cannot find path of the path solution "where.exe node" (courtesy of Lonnie Best Answer)

    它找不到路径解的路径。exe节点(由Lonnie Best Answer提供)

    E.g. if Node.js is NOT living in "Program Files (x86)" perhaps with where.exe, it is living in 'C:\Program Files\nodejs\node.exe'.

    例如,如果节点。js并不是生活在“程序文件(x86)”中。exe,它住在“C:\程序文件\nodejs\node.exe”。

    wget https://nodejs.org/download/release/latest/win-x64/node.exe -OutFile 'C:\Program Files\nodejs\node.exe'
    
  2. Now perhaps it tries to upgrade but you get another error, "node.exe is being used by another process."

    也许它试图升级,但你会得到另一个错误,"node。exe正在被另一个进程使用。

    • Close /shutdown other consoles .. command prompts and PowerShell windows, etc. Even if you're using npm in a command prompt, close it.
    • 关闭/关闭其他控制台。命令提示和PowerShell窗口等。即使您在命令提示符中使用npm,关闭它。

npm -v (3.10.8)

npm - v(3.10.8)

node -v ( v6.6.0)

节点- v(v6.6.0)

DONE. I'm at the version that I want.

完成了。我想要的版本。

#6


21  

You can update your npm to the latest stable version with the following command:

您可以使用以下命令将您的npm更新为最新的稳定版本:

 npm install npm@latest -g

Use PowerShell to run it. This command doesn't need windows administrator privileges and you can verify the result with npm -v

使用PowerShell来运行它。这个命令不需要windows管理员权限,您可以通过npm -v验证结果。

#7


18  

This works fine for me to update npm on Windows 7 x64:

这对我来说适用于Windows 7 x64上的npm更新:

  • Windows start
  • 启动Windows
  • All Programs
  • 所有程序
  • Node.js
  • node . js
  • Node.js command prompt (alternative click)
  • 节点。js命令提示符(alternative click)
  • Run as administrator

    以管理员身份运行

    $ npm -g install npm

    $ npm -g安装npm。

  • remove C:\Program Files\nodejs\npm.cmd the new npm will be at C:\Users\username\appdata\roaming\npm\npm.cmd

    删除C:\Program Files\nodejs\npm.在C:\Users\username\appdata\roaming\npm\npm.cmd cmd新npm将

Hope this helps.

希望这个有帮助。

#8


14  

Open PowerShell as administrator.

开放PowerShell管理员。

To install a first time you can use this small script to download the latest msi and run it

要安装第一次,您可以使用这个小脚本下载最新的msi并运行它。

$nodeLatest=((curl https://nodejs.org/download/release/latest/).Content | findstr x64.msi) -replace "<(.*?)>", "" -replace "\s+.+", "";
wget "https://nodejs.org/download/release/latest/$nodeLatest" -OutFile (join-path $env:TEMP node.msi); Start-Process (join-path $env:TEMP node.msi)

On future upgrades you can download just node.exe and update npm with

在以后的升级中,您可以下载节点。执行和更新npm。

wget https://nodejs.org/download/release/latest/win-x64/node.exe -OutFile 'C:\Program Files\nodejs\node.exe'
npm i -g npm

You should now have the latest node and npm.

您现在应该拥有最新的节点和npm。


I went a little further and decided to implement a nvm for Windows.

我更进一步,决定为Windows实现一个nvm。

https://github.com/brunolm/nvm

https://github.com/brunolm/nvm

Install-Module -Name power-nvm

nvm install latest
nvm default latest

#9


13  

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". Verify by running npm -v before and after the command.

前面的答案将用于安装新版本的节点。js(可能是最好的选择),但是如果您对某个特定节点有依赖关系。js版本接下来的工作是:“npm安装npm -g”。在命令之前和之后运行npm -v验证。

如何在Windows上更新npm ?

#10


10  

Use Upgrade npm on Windows

在Windows上使用升级npm。

This is the official document for a user to upgrade npm on Windows!

这是用户在Windows上升级npm的官方文件!

Here is my screenshot!

这是我的截图!

如何在Windows上更新npm ?

#11


7  

How to Update Node.js:

  1. Uninstall Node.js. Click the Start menu, type "Change or Remove a Program", click on the item shown, find Node.js in the list and uninstall it.

    卸载node . js。单击“开始”菜单,键入“更改或删除一个程序”,单击显示的项,查找节点。在列表中的js并卸载它。

  2. Delete directories, both C:\Program Files (x86)\nodejs\ and C:\Program Files\nodejs\ if they exist.

    如果存在的话,删除目录,包括c:)的程序文件(文件)、x86nodejs\和c:)。

  3. Install the latest, https://nodejs.org/en/download

    安装最新的,https://nodejs.org/en/download

    The uninstall/delete/install seems unnecessary, but it often is and this will save your time.     These instructions come from Microsoft.

卸载/删除/安装似乎是不必要的,但它经常是,这将节省您的时间。这些指令来自微软。

How to Update NPM:

    https://www.npmjs.com/package/npm-windows-upgrade

https://www.npmjs.com/package/npm-windows-upgrade

    This is the official documentation for upgrading npm on windows.

这是在windows上升级npm的官方文件。

All was tested and working on Windows 10 (2017).

所有测试都在Windows 10(2017)上进行测试。

#12


6  

For what it's worth, I had to combine several answers...

为了它的价值,我必须结合几个答案……

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

#13


4  

For me, after totally uninstalling node. 10.29, and then installing node 4.2.2, there remained a 10.29 node.exe file in my c:\windows folder.

对我来说,完全卸载节点之后。10.29,然后安装节点4.2.2,仍然有一个10.29节点。exe文件在我的c:\windows文件夹。

I found this by using the following command:

我通过以下命令找到了这个:

where.exe node

The command returned:

返回的命令:

C:\Windows\node.exe
C:\Program Files\nodejs\node.exe

So even though I had successfully installed version 4.2.2 via the msi executable, the command "node -v" would continue to return 10.29.

因此,即使我通过msi可执行文件成功安装了4.2.2版本,命令“node -v”仍将返回10.29。

I resolved this by deleting this file:

我通过删除这个文件解决了这个问题:

C:\Windows\node.exe

#14


3  

I followed @josh3737 and installed the latest MSI from the node.js homepage.

我遵循@josh3737,并从节点安装了最新的MSI。js主页。

But I had the additional problem that I still had the old node and npm on the command line. The problem was caused by the new installation, that it was installed into

但是我还有一个额外的问题,那就是在命令行上仍然有老节点和npm。这个问题是由于安装新装置引起的。

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.

新的安装程序将新目录添加到我的path变量中。所以旧的安装仍然是在路上的活动。从系统删除C:\Program Files\nodejs\后路径和C:\Users\...\AppData\从用户路径到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. And maybe this can also be fixed by first uninstalling node.js and installing the new version afterwards.

也许最小的路径是一个本地问题,与新安装无关,我有两个AppData\ npm的链接。也许这也可以通过第一个卸载节点来修复。然后再安装新版本。

#15


3  

I was also facing similar issues. I followed below mentioned steps and it worked for me:

我也面临着同样的问题。我遵循以下步骤,它为我工作:

  • go to Windows > Start > Node.js

    到Windows >启动> Node.js。

    • right click on Node.js command prompt
    • 右键单击节点。js命令提示符
    • click on Run as administrator
    • 单击Run作为管理员。
  • ping registry.npmjs.org

    ping registry.npmjs.org

  • npm view npm version

    npm视图npm版本

  • cd %ProgramFiles%\nodejs

    cd % ProgramFiles % \ nodejs

  • npm install npm@latest

    npm安装npm@latest

and npm updated successfully. Earlier I was trying for CMD and that was throwing error. may be some path issue that got resolved by running NodeJs Command Prompt. hope it'll work for you. try this.

和npm成功更新。早些时候,我在尝试CMD,那是抛出错误。可能是某个路径问题,通过运行NodeJs命令提示符得到解决。希望它对你有用。试试这个。

#16


3  

this is best tool to maintain version of NODE.Js i NVM

这是维护NODE版本的最佳工具。Js我NVM

Node Version Manager (nvm) for Windows but for Windows, with an installer. Download Now! This has always been a node version manager, not an io.js manager, so there is no back-support for io.js. However, node 4+ is supported. 如何在Windows上更新npm ?

用于Windows的节点版本管理器(nvm),但适用于Windows的安装程序。现在下载!这一直是一个节点版本管理器,而不是io。js经理,所以没有对io.j的支持。但是,支持节点4+。

#17


2  

OK guys, I read (tried on Windows) all the previous stuff and all of these answers have their own disadvantages.

好了,我读过(在Windows上试过)之前所有的东西,所有这些答案都有自己的缺点。

For the best way to update Node.js (at least for me), go to https://nodejs.org/en/ Then download the last version and install it in same folder you installed the previous version in - 1 min and it's done. You don't need to remove any old files.

为更新节点的最佳方式。js(至少对我来说),到https://nodejs.org/en/然后下载最后一个版本,并将其安装到你安装之前版本的相同文件夹中——1分钟,完成了。您不需要删除任何旧文件。

Then update npm typing in cmd: npm install --save latest-version

然后在cmd中更新npm类型:npm安装——保存最新版本。

#18


2  

To install the updates, just download the installer from the Nodejs.org site and run it again. The new version of Node.js and NPM will replace the older versions.

要安装更新,只需从Nodejs.org站点下载安装程序并再次运行它。新版本的节点。js和NPM将取代旧版本。

#19


1  

This works fine for me

这对我来说没问题。

  1. Run Command Prompt as Administrator

    作为管理员运行命令提示符。

  2. Navigate to the folder containing nodejs (eg. C:\Program Files\nodejs)
  3. 导航到包含nodejs的文件夹(如。C:\Program Files\ nodejs)
  4. Run Powershell -ExecutionPolicy Unrestricted

    运行Powershell -ExecutionPolicy无限制的

  5. Run npm-windows-upgrade

    运行npm-windows-upgrade

  6. This will show list of versions available to install. Just select your desired version by moving up/down key & Press Enter.

    This'll update your npm
  7. 这将显示可用于安装的版本列表。选择你想要的版本,通过向上/向下键和按回车。这将更新你的npm
  8. To check the current version of npm

    Run npm --version

    运行npm——版本

Command Prompt Screenshot

命令提示符截图

#20


1  

follow these steps for window 10 or window 8

按照下面的步骤操作10或8窗口。

  • press WIN + R and type cmd and enter
  • 按WIN + R和type cmd并输入。
  • npm i -g npm@next
  • npm我- g npm@next
  • npm i -g npm@next OR npm i -g node@{version}
  • npm i -g npm@next或npm i -g node@{version}
  • Remove environment path C:\Program Files\nodejs from envrionment variable PATH.
  • 删除环境路径C:\Program Files\nodejs从环境变量路径。
  • type refreshenv in cmd
  • 类型refreshenv cmd

Now you will have your new version which you installed.

现在您将拥有您安装的新版本。

Note: If you don't remove path. You will see the previous version of node.

注意:如果您不删除路径。您将看到以前版本的节点。

#21


0  

You can use these commands:

您可以使用以下命令:

npm cache clean
npm update -g [package....]

If you are upgrading from a previous version of node, then you will want to update all existing global packages. You can also specify the package name to be updated.

如果您正在从先前版本的节点升级,那么您将需要更新所有现有的全局包。您还可以指定要更新的包名称。

#22


0  

This might help someone. Neither "npm-windows-upgrade" nor the installer alone did it for me. Powershell was still using an older version of node and npm.

这可能会帮助别人。无论是“npm- windowsupgrade”还是安装程序都没有为我做。Powershell仍然使用老版本的节点和npm。

So this is what I did (worked for me): 1. Download the latest installer from nodejs.org. Install node. It will update your node; everywhere (Powershell, cmd etc.). 2. Install the npm-windows-upgrade package (npm install -g npm-windows-upgrade) and run npm-windows-upgrade.

这就是我所做的(为我工作):1。从nodejs.org下载最新的安装程序。安装节点。它将更新您的节点;到处(Powershell cmd等)。2。安装npm-windows升级包(npm安装- gnpm - windowsupgrade)并运行npm- windowsupgrade。

I didn't uninstall anything and didn't set any paths.

我没有卸载任何东西,也没有设置任何路径。

#23


0  

In my case, I discovered that I had two copies of Node.js installed. One under "C:\Program Files\nodejs" and another under "C:\Program Files (x86)\nodejs".

在我的例子中,我发现我有两个节点副本。js安装。一个在“C:\程序文件\nodejs”下,另一个在“C:\程序文件(x86)\nodejs”下。

#24


0  

The easiest way I found so far to update Node.js is using Chocolatey. Use Chocolatey to install or update the latest version of Node.js on Windows:

到目前为止我发现的最简单的更新节点的方法。js使用巧克力色。使用Chocolatey来安装或更新最新版本的节点。js在Windows上:

Step 1: First, ensure that you already have Chocolatey installed. If not, use an administrative shell to install chocolatey through cmd.exe or PowerShell.exe. For more information, visit: https://chocolatey.org/docs/installation

步骤一:首先,确保你已经安装了巧克力。如果没有,请使用管理shell通过cmd安装巧克力。exe或PowerShell.exe。有关更多信息,请访问:https://chocolatey.org/docs/installation。

Step 2: Install with cmd.exe. Run the following command:

步骤2:使用cmd.exe安装。运行以下命令:

@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

To install with PowerShell.exe, visit: https://chocolatey.org/docs/installation

PowerShell的安装。exe,请访问:https://chocolatey.org/docs/installation

Step 3: Install or Update with following commands on cmd.exe (on administrative mode)

步骤3:在cmd上安装或更新以下命令。exe(行政模式)

To Install Node.js: cinst nodejs.install

安装节点。js:cinst nodejs.install

To Update Node.js: cup nodejs.install

更新节点。js:杯nodejs.install

#25


0  

For NodeJS

对于NodeJS

Download required node version msi from here and install

从这里下载所需的节点版本msi并安装。

for Npm

对于Npm

Run PowerShell as Administrator

以管理员身份运行PowerShell

Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
npm install -g npm-windows-upgrade
npm-windows-upgrade

#26


0  

1. Installing latest npm version

1。npm安装最新版本

npm install –g npm@latest 

(You can type "npm –version" to check that)

(你可以输入“npm -版本”来检查)


2. Installing Node

2。安装节点

a. Install node new version via following URL: https://nodejs.org/en/download/current/ Follow the default choices
b. Remove C:\Users\\AppData\Roaming\NPM
c. Remove C:\Users\\AppData\Roaming\npm-cache

。安装节点新版本通过以下URL:https://nodejs.org/en/download/current/按照默认选择b。删除C:\Users\ \ AppData \漫游\ NPM c。删除C:\Users\ \ AppData \ \ npm-cache徘徊


Optionally:

(可选):

d. (Delete node_modules folder in your current project folder)
e. npm cache verify
f. npm install

d.(删除当前项目文件夹中的node_modules文件夹)e. npm缓存验证f. npm安装。

#27


0  

To upgrade, run: npm install npm@latest -g.

升级,运行:npm安装npm@latest -g。

This will upgrade to the latest stable version. The time I wrote this answer, the stable version is 5.8.0.

这将升级到最新的稳定版本。我写这个答案的时候,稳定的版本是5.8.0。

You can also find this information in the footer section of npm docs page. https://docs.npmjs.com/getting-started/what-is-npm

您也可以在npm文档页的页脚部分找到这些信息。https://docs.npmjs.com/getting-started/what-is-npm

#28


-1  

This is what worked for me.

这就是我的工作。

  1. Open a local folder other than the one in which nodejs is installed.
  2. 打开一个本地文件夹,而不是安装nodejs的本地文件夹。
  3. Install npm in that folder with command npm install npm
  4. 在该文件夹中安装npm,命令npm安装npm。
  5. Navigate to the folder containing node js. (C:\Program Files\nodejs\node_modules)
  6. 导航到包含node js的文件夹。(C:\ Program Files \ nodejs \ node_modules)
  7. Delete the npm folder and replace it with the npm and bin folders in the local folder.
  8. 删除npm文件夹,并将其替换为本地文件夹中的npm和bin文件夹。
  9. Run npm -v. Now you would get updated version for npm.
  10. 运行npm - v。现在你会得到npm的更新版本。

Note: I tried installing npm directly in "C:\Program Files\nodejs\node_modules" but it created errors.

注意:我尝试直接在“C:\程序文件\nodejs\node_modules”中安装npm,但它造成了错误。

#29


-2  

  1. Start
  2. 开始
  3. Search for windows powershell
  4. 寻找windows powershell
  5. Right click and run as administrator
  6. 右击并作为管理员运行。
  7. Type: where.exe node (returns the path of node.exe in your system. Copy this)
  8. 类型:。exe节点(返回节点路径)。exe在您的系统。复制这个)
  9. wget https://nodejs.org/download/release/latest/win-x64/node.exe -OutFile 'PATH-OF-NODE.EXE_WHICH_YOU_COPIED_JUST_NOW'
  10. wget https://nodejs.org/download/release/latest/win-x64/node.exe输出文件“PATH-OF-NODE.EXE_WHICH_YOU_COPIED_JUST_NOW”
  11. To check if it has worked, go to your Git bash/Normal command prompt and type: node -v
  12. 要检查它是否有效,请访问Git bash/Normal命令提示符和类型:node -v。
  13. Here you can find the current version of node: https://nodejs.org/en/blog/release/
  14. 在这里您可以找到当前版本的节点:https://nodejs.org/en/blog/release/。