NPM的新版本已经安装,但旧仍在使用
我被这个当我安装了一个项目依赖关系:
Update available 5.7.1 → 5.8.0 │
│ Run npm i npm to update
然后,我这样做:
$ npm i npm
npm WARN [email protected] requires a peer of react@>=0.11.0 || ^0.14.0-rc but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
+ [email protected]
added 523 packages from 726 contributors in 12.75s
但为什么还是老版本?
$ npm --version
5.7.1
回答如下:
但为什么还是老版本?
默认情况下,NPM安装在本地node_modules/
目录软件包。由于npm i npm
是简写npm install npm
,它会在本地安装最新版本的防范机制。
然而,在shell中运行npm
时,壳拿起你的npm
,这可能是全球安装$PATH
。
要更新NPM的全球安装,运行:
npm install --global npm
你也可能会想删除NPM减少膨胀的本地安装:
npm uninstall npm
见How can I update Node.js and npm to the next versions?关于更新的详细信息。