weixin_41568110
七度&光
采纳率25%
2013-08-23 21:26

如何在 Windows 上更新 npm?

已采纳

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?

转载于:https://stackoverflow.com/questions/18412129/how-can-i-update-npm-on-windows

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

28条回答

  • csdnceshi61 derek5. 6年前

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

    Run PowerShell as Administrator

    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.

    点赞 30 评论 复制链接分享
  • weixin_41568127 ?yb? 8年前

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

    点赞 27 评论 复制链接分享
  • csdnceshi60 ℡Wang Yan 7年前

    To update NPM, this worked for me:

    • Navigate in your shell to your node installation directory, eg C:\Program Files (x86)\nodejs
    • run npm install npm (no -g option)
    点赞 27 评论 复制链接分享
  • weixin_41568126 乱世@小熊 3年前

    follow these steps for window 10 or window 8

    • press WIN + R and type cmd and enter
    • npm i -g npm@next
    • npm i -g npm@next OR npm i -g node@{version}
    • Remove environment path C:\Program Files\nodejs from envrionment variable PATH.
    • type refreshenv in 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.

    点赞 9 评论 复制链接分享
  • csdnceshi54 hurriedly% 5年前

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

    • go to Windows > Start > Node.js

      • right click on Node.js command prompt
      • click on Run as administrator
    • ping registry.npmjs.org

    • npm view npm version

    • cd %ProgramFiles%\nodejs

    • npm install 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.

    点赞 9 评论 复制链接分享
  • weixin_41568110 七度&光 4年前

    For NodeJS

    Download required node version msi from here and install

    for Npm

    Run PowerShell as Administrator

    Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
    npm install -g npm-windows-upgrade
    npm-windows-upgrade
    
    点赞 9 评论 复制链接分享
  • weixin_41568183 零零乙 7年前

    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.

    Enter image description here

    点赞 9 评论 复制链接分享
  • csdnceshi80 胖鸭 7年前

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

    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

    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.

    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.

    点赞 9 评论 复制链接分享
  • csdnceshi70 笑故挽风 3年前

    Powershell does not execute npm directly, I suggest using

    .\npm install -g npm-windows-upgrade
    .\npm-windows-upgrade
    

    and it failed with:

    You wanted to install npm 6.1.0, but the installed version is 3.10.10.

    A common reason is an attempted "npm install npm" or "npm upgrade npm". As of today, the only solution is to completely uninstall and then reinstall Node.js. For a small tutorial, please see http://aka.ms/fix-npm-upgrade.

    Please consider reporting your trouble to http://aka.ms/npm-issues.

    http://aka.ms/fix-npm-upgrade <-- this is a dead link

    点赞 9 评论 复制链接分享
  • weixin_41568127 ?yb? 4年前

    1. Installing latest npm version

    npm install –g npm@latest 
    

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


    2. Installing Node

    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


    Optionally:

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

    点赞 7 评论 复制链接分享
  • weixin_41568183 零零乙 6年前

    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.

    点赞 7 评论 复制链接分享
  • csdnceshi73 喵-见缝插针 4年前

    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.

    点赞 7 评论 复制链接分享
  • csdnceshi62 csdnceshi62 5年前

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

     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

    点赞 7 评论 复制链接分享
  • csdnceshi80 胖鸭 5年前

    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

    1. Run this to update NPM:

      Run PowerShell as administrator

      npm i -g npm    // This works
      

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

      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:

    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 ...

    Otherwise

    You might need to set your proxy

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

    2 possible errors

    1. 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'
      
    2. 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)

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

    点赞 6 评论 复制链接分享
  • csdnceshi74 7*4 4年前

    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.

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

    3. Install the latest, 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

        This is the official documentation for upgrading npm on windows.

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

    点赞 5 评论 复制链接分享
  • weixin_41568184 叼花硬汉 4年前

    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:

    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

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

    @"%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

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

    To Install Node.js: cinst nodejs.install

    To Update Node.js: cup nodejs.install

    点赞 4 评论 复制链接分享
  • csdnceshi80 胖鸭 4年前

    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".

    点赞 4 评论 复制链接分享
  • csdnceshi53 Lotus@ 7年前

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

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

    > choco install nodejs
    

    Update to the latest version

    > choco update nodejs
    

    and for npm

    > choco update npm
    
    点赞 4 评论 复制链接分享
  • csdnceshi50 三生石@ 5年前

    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.

    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.

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

    点赞 3 评论 复制链接分享
  • csdnceshi75 衫裤跑路 5年前

    this is best tool to maintain version of NODE.Js i 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. enter image description here

    点赞 2 评论 复制链接分享
  • weixin_41568208 北城已荒凉 6年前

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

    • Windows start
    • All Programs
    • Node.js
    • Node.js command prompt (alternative click)
    • Run as administrator

      $ npm -g install npm

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

    Hope this helps.

    点赞 2 评论 复制链接分享
  • csdnceshi57 perhaps? 6年前

    Open PowerShell as administrator.

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

    $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

    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.


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

    https://github.com/brunolm/nvm

    Install-Module -Name power-nvm
    
    nvm install latest
    nvm default latest
    
    点赞 1 评论 复制链接分享
  • csdnceshi72 谁还没个明天 5年前

    Use Upgrade npm on Windows

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

    Here is my screenshot!

    Enter image description here

    点赞 1 评论 复制链接分享
  • weixin_41568126 乱世@小熊 7年前

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

    1. Uninstall Node.js in control panel Add/remove programs.
    2. Delete directories, both C:\Program Files (x86)\nodejs\ and C:\Program Files\nodejs\ if they exist.
    3. Install the latest version, http://nodejs.org/download/
    点赞 1 评论 复制链接分享
  • csdnceshi61 derek5. 5年前

    This works fine for me

    1. Run Command Prompt as Administrator

    2. Navigate to the folder containing nodejs (eg. C:\Program Files\nodejs)
    3. Run Powershell -ExecutionPolicy Unrestricted

    4. Run npm-windows-upgrade

    5. 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
    6. To check the current version of npm

      Run npm --version

    Command Prompt Screenshot

    点赞 1 评论 复制链接分享
  • csdnceshi74 7*4 6年前

    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.

    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.

    I resolved this by deleting this file:

    C:\Windows\node.exe
    
    点赞 1 评论 复制链接分享
  • weixin_41568134 MAO-EYE 5年前
    1. Start
    2. Search for windows powershell
    3. Right click and run as administrator
    4. Type: where.exe node (returns the path of node.exe in your system. Copy this)
    5. wget https://nodejs.org/download/release/latest/win-x64/node.exe -OutFile 'PATH-OF-NODE.EXE_WHICH_YOU_COPIED_JUST_NOW'
    6. To check if it has worked, go to your Git bash/Normal command prompt and type: node -v
    7. Here you can find the current version of node: https://nodejs.org/en/blog/release/
    点赞 评论 复制链接分享
  • csdnceshi67 bug^君 5年前

    This is what worked for me.

    1. Open a local folder other than the one in which nodejs is installed.
    2. Install npm in that folder with command npm install npm
    3. Navigate to the folder containing node js. (C:\Program Files\nodejs\node_modules)
    4. Delete the npm folder and replace it with the npm and bin folders in the local folder.
    5. Run npm -v. Now you would get updated version for npm.

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

    点赞 评论 复制链接分享