最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to update npm in windows? - Stack Overflow

programmeradmin0浏览0评论

I am looking for a way to upgrade my npm, I follow the option 3 for windows in here npm docs. but when I install it it said npm.exe already in nodejs folder. I try to overwrite it with --force but it still not overwritten. How to do it correctly? also how to update node?

I am looking for a way to upgrade my npm, I follow the option 3 for windows in here npm docs. but when I install it it said npm.exe already in nodejs folder. I try to overwrite it with --force but it still not overwritten. How to do it correctly? also how to update node?

Share Improve this question edited Jul 28, 2020 at 11:41 Farhan Khalifa asked Jul 28, 2020 at 11:29 Farhan KhalifaFarhan Khalifa 331 gold badge1 silver badge8 bronze badges 7
  • Install latest node.js – Adam Orłowski Commented Jul 28, 2020 at 11:31
  • yes i already have it – Farhan Khalifa Commented Jul 28, 2020 at 11:31
  • Doesn’t npm i-g npm work? – evolutionxbox Commented Jul 28, 2020 at 11:31
  • Then what is the problem? – Adam Orłowski Commented Jul 28, 2020 at 11:32
  • You should look at nvm for windows and let that manage your npm and node versions. Much easier for upgrading and switching – Enslev Commented Jul 28, 2020 at 11:33
 |  Show 2 more ments

4 Answers 4

Reset to default 8

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.

  • Upgrades npm in-place, where node installed it.
  • Easy updating, update to the latest by running npm-windows-upgrade -p -v latest.
  • Does not modify the default path.
  • Does not change the default global package location.
  • Allows easy upgrades and downgrades.
  • Officially remended by the NPM team.
  • A list of versions matched between NPM and NODE (https://nodejs/en/download/releases/) - but you will need to download NODE INSTALLER and run that to update node (https://nodejs/en/)

There is a tool, nvm, that solves your problem quite easly. There is also a Windows version, is not as cool as the linux/mac version but it works fine anyway

I suggest using option 1. Go to environment system variables and add "%appdata%\npm" to path like this: edit path

Then updated npm files should be loaded before those you installed with node

  1. Node.js v16 or higher?

    npm install -g npm
    
  2. Node.js v14 or below?

    Consider updating to latest LTS release of Node.js
    
    npm-windows-upgrade
    
发布评论

评论列表(0)

  1. 暂无评论