Command to remove all npm modules globally?

2019-01-04 04:18发布

Is there a command to remove all global npm modules? If not, what do you suggest?

标签: node.js npm
17条回答
可以哭但决不认输i
2楼-- · 2019-01-04 04:57

If you would like to remove all the packages that you have installed, you can use the npm -g ls command to find them, and then npm -g rm to remove them.

查看更多
仙女界的扛把子
3楼-- · 2019-01-04 04:57

if you have Intellij Webstorm you can use its built-in graphical package manager.

open it as root and create an emtpy project. go to

File > Settings > Language and Frameworks > Node.js and NPM

there you will see all the installed packages. Uninstalling is easy, you can select and deselect any package you want to uninstall, Ctrl+a woks as well.

查看更多
女痞
4楼-- · 2019-01-04 04:58
sudo npm list -g --depth=0. | awk -F ' ' '{print $2}' | awk -F '@' '{print $1}'  | sudo xargs npm remove -g

worked for me

  • sudo npm list -g --depth=0. lists all top level installed
  • awk -F ' ' '{print $2}' gets rid of ├──
  • awk -F '@' '{print $1}' gets the part before '@'
  • sudo xargs npm remove -g removes the package globally
查看更多
我命由我不由天
5楼-- · 2019-01-04 04:58

Just put in your console:

sudo npm list -g --depth=0. | awk -F ' ' '{print $2}' | awk -F '@' '{print $1}' | sudo xargs npm remove -g

Its work for me...

查看更多
▲ chillily
6楼-- · 2019-01-04 05:00

It's as simple as: rm -rf ~/.npm

查看更多
够拽才男人
7楼-- · 2019-01-04 05:02

The following command removes all global npm modules. Note: this does not work on Windows. For a working Windows version, see Ollie Bennett's Answer.

npm ls -gp --depth=0 | awk -F/ '/node_modules/ && !/\/npm$/ {print $NF}' | xargs npm -g rm

Here is how it works:

  • npm ls -gp --depth=0 lists all global top level modules (see the cli documentation for ls)
  • awk -F/ '/node_modules/ && !/\/npm$/ {print $NF}' prints all modules that are not actually npm itself (does not end with /npm)
  • xargs npm -g rm removes all modules globally that come over the previous pipe
查看更多
登录 后发表回答