node.js 如何全局删除已安装的 npm 包?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35847868/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to Remove Installed npm packages globally?
提问by user1272965
I think I've been using npm incorrectly, most of the time installing globally (with -g) instead of locally (with -save). Now I have a long list of global packages that I want/ought** to clean up.
我想我一直在错误地使用 npm,大部分时间是全局安装(使用 -g)而不是本地安装(使用 -save)。现在我有一长串想要/应该**清理的全局包。
(**I'm new to this, and in addition to being OCD-tidy, I don't want to accidentally use a package in an app without explicitly mentioning it, otherwise it might become a tough puzzle to deploy someplace.).
(**我是新来的,除了 OCD 整洁之外,我不想在没有明确提及的情况下意外地在应用程序中使用包,否则在某个地方部署可能会成为一个难题。)。
I understand that I can use npm uninstall <package> -gto do the actual removal, but how do I decide what should stay?There's a looong list of things named like "[email protected]" and so on.
我知道我可以npm uninstall <package> -g用来进行实际的移除,但我如何决定应该保留什么?有一长串类似“[email protected]”之类的东西。
Is there a way to determine if a project is using it, or if its the kind of thing I need globally? It will be a long day going to the docs for each one. Or maybe there's a rule of thumb, like: "one typically needs x, y, and z, and you can delete the rest"?
有没有办法确定一个项目是否正在使用它,或者它是否是我在全球范围内需要的那种东西?为每个人查看文档将是漫长的一天。或者也许有一个经验法则,比如:“一个人通常需要 x、y 和 z,你可以删除其余的”?
Also, once I have a removal list, is my only choice to execute all of those unistall -g commands one by one?
另外,一旦我有了删除列表,我是否唯一的选择是逐一执行所有这些 unistall -g 命令?
回答by silwalprabin
You can use:
npm uninstall -g package_to_uninstall
您可以使用:
npm uninstall -g package_to_uninstall
See:https://docs.npmjs.com/cli/uninstallIf you prefer video: https://docs.npmjs.com/getting-started/uninstalling-global-packages
请参阅:https: //docs.npmjs.com/cli/uninstall如果您更喜欢视频:https: //docs.npmjs.com/getting-started/uninstalling-global-packages
If you want to remove all packages; There is trick: Please follow below link: Command to remove all npm modules globally?
如果要删除所有包;有一个技巧:请按照以下链接: 命令全局删除所有 npm 模块?
回答by Homam Bahrani
this didn't work on ubuntu for pm2, I had to run npm remove pm2 -g
这在 ubuntu for pm2 上不起作用,我不得不运行 npm remove pm2 -g

