Command to remove all npm modules globally?


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

2/14/2012 8:07:36 PM

Accepted Answer

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
5/23/2017 12:18:22 PM

For those using Windows, the easiest way to remove all globally installed npm packages is to delete the contents of:


You can get here quickly by typing %appdata% (either in explorer, run prompt, or start menu).

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow