To uninstall a npm module from project node_modules folder, run:
npm uninstall <module> --save
Note that npm modules should be uninstalled from the same directory that contains the node_modules folder when running this command. The --save option will also remove it from your package.json
One can also remove a local dependency/module installation, by deleting its directory from the local node_modules folder. Yes, it’s safe to delete dependencies there.
To uninstall a npm module that was installed globally, run:
npm uninstall -g <module>
It doesn’t matter where you run this command from.
To install a npm module, run: (only meant as reference)
npm install <module>
…or:
npm install (if there’s a package.json file at the root of your project)
…or:
npm install <module> --save-dev (if you want to add a minimum version to the dependency)
Good things to know about Grunt:
- If you have installed
gruntstable before February 18, 2013 (the daygrunt v0.4.xwas released), you might have an oldergruntversion still lingering in your system. That’s becausegruntversions lower than0.4.xwere installed globally, which caused a lot of pain when upgrading/maintaining versions. -
gruntandgrunt-cliare two different things.grunt(without the “cli”) is usually installed at the project level (when listed as adevDependencyinpackage.json) by runningnpm install. That’s also known as a local installation.grunt-cliis the underlying foundation on which local versions ofgruntrun in different projects/folders. It can be installed locally, but is more useful when installed globally, once.
-
gruntis only installed locally (by runningnpm install grunt). grunt-cliis preferably installed globally (by runningnpm install -g grunt-cli).grunt-cliofficialnpmpage still warns against installinggrunt(without the cli) globally.- If you want to uninstall the global installation of
grunt-cli, runnpm uninstall -g grunt-cli. This issue on gruntjs’s project supports this procedure. - Never install
gruntglobally (by runningnpm install -g grunt).
On npm and sudo
sudo doesn’t play well with npm. Only use it if you must. Below are two quotes on the advantages and disadvantages on its use:
Quoting Isaac Z. Schlueter on his Introduction to npm article:
I strongly encourage you not to do package management with sudo!
Packages can run arbitrary scripts, which makes sudoing a package manager command
as safe as a chainsaw haircut. Sure, it’s fast and definitely going to cut
through any obstacles, but you might actually want that obstacle to stay there.I recommend doing this once instead:
sudo chown -R $USER /usr/localThat sets your user account as the owner of the /usr/local directory, so that you can
just issue normal commands in there. Then you won’t ever have to use sudo when you
install node or issue npm commands.It’s much better this way. /usr/local is supposed to be the stuff you installed, after all.
Yet another catch mentioned by Andrei Karpushonak:
There are certain security concerns and functionality limitations
regarding changing the ownership of /usr/local to the current user:
- if there is another user on the machine who could use global
npm packages – do not change the ownership of /usr/local- https://apple.stackexchange.com/questions/1393/are-my-permissions-for-usr-local-correct
- https://askubuntu.com/questions/261326/is-it-safe-to-chown-usr-local
Having said that, if you want to install global module without using sudo,
I don’t see any better solution (from pragmatic point of view) than mentioned.
Security vs easy of use is very broad topic, and there is no easy answer for that
– it just depends on your requirements.