24

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.

(**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.).

I understand that I can use npm uninstall <package> -g to 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.

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"?

Also, once I have a removal list, is my only choice to execute all of those unistall -g commands one by one?

7
  • 1
    Generally, if you run it from the command line, it's a global package, whereas if you require() it in a project, it should be local. Commented Mar 7, 2016 at 15:43
  • I just learned that most of the packages are installed as parts of others, and (I think) will get removed when I remove the parent. The list isn't as long as I thought, and I recognize most of the names on the left side of the list. I guess I should delete this question, but stackoverflow says I can't because it has an answer. Commented Mar 7, 2016 at 16:01
  • 1
    It was a valid question IMO - no harm in leaving it up. Commented Mar 7, 2016 at 16:04
  • Why do you think installing globally is the wrong way? (I too am a new user, and I too avoid installing locally, but is this wrong?) Commented Mar 7, 2016 at 18:16
  • 1
    @Ayyash - If you globally install a package and then use it in two projects, you can't update it for one and not the other, whereas if you install it locally to a project, you can have a separate version in each project without them interfering. Also, if you have your packages locally installed, and saved to your package.json, it means you don't have to copy node_modules if you want to develop on another computer; you just have to run npm install, and it'll pull them all in automatically. Locally installing packages just generally makes tracking/managing a project's dependencies easier. Commented Mar 8, 2016 at 10:28

2 Answers 2

31

You can use: npm uninstall -g package_to_uninstall

See:https://docs.npmjs.com/cli/uninstall If you prefer video: 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?

Sign up to request clarification or add additional context in comments.

1 Comment

Related q: how do I remove any associated scripts in my /usr/local/bin ?
0

this didn't work on ubuntu for pm2, I had to run npm remove pm2 -g

1 Comment

npm remove is an alias of npm uninstall, and rm, r, un and unlink, Check npm help uninstall for more info.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.