如何更新全局安装的npm软件包

时间:2018-11-10 10:54:36

标签: reactjs npm npm-start

命令:npm outdated -g

输出:

Package           Current  Wanted  Latest  Location

@angular/cli        1.3.1   1.7.4   7.0.5
create-react-app    1.5.2   1.5.2   2.1.1
eslint              5.6.0   5.9.0   5.9.0
expo-cli            2.2.0   2.3.8   2.3.8
gulp-cli            1.4.0   1.4.0   2.0.1
how-to-npm          2.5.0   2.5.1   2.5.1
mocha               3.5.0   3.5.3   5.2.0
nodemon            1.18.3  1.18.6  1.18.6
now                11.4.6  11.5.2  12.0.1
serve              10.0.1  10.0.2  10.0.2
typescript          2.4.2   2.9.2   3.1.6
yarn                1.9.4  1.12.3  1.12.3

如何在npm中更新这些过时的软件包?

3 个答案:

答案 0 :(得分:8)

如果要更新所有全局软件包

npm update -g

如果您要更新特定的全局软件包

npm update -g <package_name>

答案 1 :(得分:0)

要添加到Mohit的答案中,如果您使用的是NPM 2.6或更低版本,则在该情况下,有几个脚本很容易处理更新:https://gist.github.com/othiym23/4ac31155da23962afd0e

您需要创建描述的两个文件,然后在命令提示符下运行它们。这将更新所有软件包。要有选择地进行更新,请向下滚动至2014年10月20日起Dylang的注释的上方链接页面。2014年11月6日起的以下注释将为您提供Windows环境的脚本。

考虑到长期维护,最好的解决方案可能是先运行以下命令来更新NPM:

npm install npm@latest -g

有关流程的相当全面的文档可以在https://docs.npmjs.com/updating-packages-downloaded-from-the-registry

中找到

答案 2 :(得分:0)

要将所有全局包自动更新到“最新”版本:

npx npm-check --global --update-all

这会将所有全局包更新到“最新”版本。 More information is available about npm-check,包括执行交互式更新、排除软件包等的能力。


改为仅将全局包更新为 npm outdated --global 显示的“Wanted”版本(因为全局安装的包被视为使用指定的插入符号 semver 范围安装):< /p>

npm update -g

最后,如果您想将软件包更新(安装)到“最新”或“想要”之外的版本:

npm install --global <pkg>@<version>
相关问题