我试了一下:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
...但这并没有起作用。
如何在Windows上做到这一点?
我试了一下:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
...但这并没有起作用。
如何在Windows上做到这一点?
当前回答
到目前为止,我发现更新Node.js最简单的方法是使用Chocolatey。 使用Chocolatey在Windows上安装或更新最新版本的Node.js:
步骤1:首先,确保已经安装了Chocolatey。如果没有,请使用管理shell通过cmd.exe或PowerShell.exe安装chocolatey。欲了解更多信息,请访问:https://chocolatey.org/docs/installation
步骤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"
要使用PowerShell.exe安装,请访问:https://chocolatey.org/docs/installation
步骤3:在cmd.exe上使用以下命令安装或更新(在管理模式下)
安装Node.js: cinst nodejs.install
更新Node.js: cup nodejs.install
其他回答
到目前为止,我发现更新Node.js最简单的方法是使用Chocolatey。 使用Chocolatey在Windows上安装或更新最新版本的Node.js:
步骤1:首先,确保已经安装了Chocolatey。如果没有,请使用管理shell通过cmd.exe或PowerShell.exe安装chocolatey。欲了解更多信息,请访问:https://chocolatey.org/docs/installation
步骤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"
要使用PowerShell.exe安装,请访问:https://chocolatey.org/docs/installation
步骤3:在cmd.exe上使用以下命令安装或更新(在管理模式下)
安装Node.js: cinst nodejs.install
更新Node.js: cup nodejs.install
在Windows上使用升级npm
这是用户在Windows上升级npm的官方文档!
这是我的截图!
像一些人一样,我需要组合多个答案,我还需要设置一个代理。
这对任何人都适用。我有零愿望运行EXE文件或MSI文件..卸载/重新安装,或手动删除文件和文件夹。这就是1999年的情况:P
运行这个来更新NPM: 以管理员身份运行PowerShell npm i -g npm // 我不认为这段代码实际上升级了你下面的npm版本 Set-ExecutionPolicy unlimited -Scope CurrentUser -Force NPM install -g NPM -windows-upgrade npm-windows-upgrade (由“罗伯特”回答提供)
运行这个来更新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)
如果你得到' wget:无法找到路径....的一部分**,见下文…向下滚动。阅读网络响应…它至少要通过防火墙/代理(如果你有一个或已经运行了代码,请通过…)
否则
您可能需要设置代理
npm config set proxy "http://proxy.yourcorp.com:811" (yes, use quotes)
2个可能的错误
It cannot find path of the path solution "where.exe node" (courtesy of 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'. wget https://nodejs.org/download/release/latest/win-x64/node.exe -OutFile 'C:\Program Files\nodejs\node.exe' Now perhaps it tries to upgrade but you get another error, "node.exe is being used by another process." Close /shutdown other consoles .. command prompts and PowerShell windows, etc. Even if you're using npm in a command prompt, close it.
npm -v (3.10.8)
Node -v (v6.6.0)
完成了。我得到了我想要的版本。
下载并运行最新的MSI。MSI会更新你安装的节点和npm。
不管怎样,我必须把几个答案结合起来……
在控制面板中卸载Node.js。 删除目录C:\Program Files (x86)\nodejs\和C:\Program Files\nodejs\(如果存在)。 安装最新版本http://nodejs.org/download/