How do I update npm on Windows?

后端 未结 12 810
时光说笑
时光说笑 2020-12-04 09:37

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?

npm install

相关标签:
12条回答
  • 2020-12-04 09:57

    You need to follow the Windows upgrade instructions ( https://docs.npmjs.com/try-the-latest-stable-version-of-npm )

    tl;dr - npm -g install npm does work, but the old version of npm is still in your PATH.

    To fix this, do one of these:

    Option 2: remove both of

    C:\Program Files (x86)\nodejs\npm

    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:

    npm install npm@latest

    *There is an npm package that automate this Option 3:

    npm install -g npm-win-upgrade

    0 讨论(0)
  • 2020-12-04 10:02

    For update node npm on Windows

    I have to delete node in:

    C:\Users**YOUR USER**\AppData\Roaming

    And reinstall node

    0 讨论(0)
  • 2020-12-04 10:04

    There May be many ways to update your npm in Windows

    Way 1

    1. Open you power shell as Administrator and run following commands step by step.
    2. Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
    3. npm install -g npm-windows-upgrade
    4. npm-windows-upgrade
    5. Here you can select your preferred version of npm
    6. Ready to go !

    Way 2

    1. You can simply upgrade to the latest npm version with following command
    2. npm install npm@latest -g
    3. or if you want a specific version of npm simply run
    4. npm install npm@{version} -g for example npm install npm@3.3.12 -g

    Now simply run npm --version or npm -v to know your current version of npm

    3.3.12 is my preferred version of npm that best suits for approximately every package.

    0 讨论(0)
  • 2020-12-04 10:04

    You need to follow the Windows upgrade instructions

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

    First, ensure that you can execute scripts on your system by running the following command from an elevated PowerShell. To run PowerShell as Administrator, click Start, search for PowerShell, right-click PowerShell and select Run as Administrator.

    1. Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
    2. npm install --global --production npm-windows-upgrade
    3. npm-windows-upgrade

    Want to just install the latest version? 1.npm-windows-upgrade --npm-version latest

    0 讨论(0)
  • 2020-12-04 10:06

    So, TL;DR; this worked:

    1. Uninstall node

    2. From a command prompt, run where npm

    3. If you had npm installed via chocolatey, you'll see a path like C:\ProgramData\chocolatey\bin\npm.exe - DELETE it!
    4. Now install NodeJS using the appropriate MSI from https://nodejs.org/en/download/
    5. 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)

    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.

    =======

    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:

    1. Open your favourite console (CMD, Cmder, PowerShell)
    2. Type nvm install 6.10.2 (to install node version 6.10.2)
    3. To see the currently active version, type nvm list. This prints something like below:

      6.9.3   
    * 6.9.2 (Currently using 64-bit executable)
      6.9.1
      6.10.2

    0 讨论(0)
  • 2020-12-04 10:07

    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:

    1. Remove NPM/Node from your Environment Variables, both for user and system.
    2. Close your open console if you have one open, then open a console as administrator
    3. Change directories to %USERPROFILE% -- that's a window's environment variable that takes you to C:\Users\CurrentlyLoggedInUser
    4. Run from the console in %USERPROFILE%, "C:\Program Files\nodejs\npm" install npm -g (you might have yours in the x86 folder)
    5. If this solution would work for you, step 4 would have worked, and npm -v will show a an up-to-date version
    6. 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

    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.

    0 讨论(0)
提交回复
热议问题