npm update -g

Justin Moh
2 min readMar 15, 2015

--

Do not try it. You will break things up.

There is a command that updates all global packages, npm update -g, but it is currently not recommended. Until that issue is fixed, you can use this script to update all outdated global packages.

I have already read about it on npmjs.com, but still, because there’re so many package managers I’ve been using, I typed these in my Terminal.

$ npm update -g

You’ll get some weird output, then the next thing you find, is,

-bash: npm: command not found

OMFG.

I know I’ve just ran into some kind of special hell — I like this word, not relevant to the topic but, from here.

After some googles I find something useful, none of them however, provide a quick fix:

NPM GitHub: npm update -g has broken npm #4099

StackOverflow: Permissions during node installation

StackOverflow: Uninstall node + npm

brock / nodereinstall.sh

NPM: Cleaning the Slate

So I’ll uninstall npm and node

There’s no one-click solution to clean uninstall npm, you’ll have many left-overs. Nevertheless, you could still uninstall npm by

$ npm uninstall npm -g

But since npm is broken right now, you will need to remove it manually. Also, you may want to keep a note of what you’ve been installed with npm, so that you can install them again once you got another working npm.

My way of doing it, simply list the directory and save it in a text file for a reference.

$ ls /usr/local/lib/node_modules >> InstalledNpmPackages.text

Let’s start from node.

$ brew uninstall node
$ brew prune

Now look for npm related stuff. You could probably try:

$ rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/npm*
$ rm -rf /usr/local/bin/{node*,npm}
$ rm -rf ~/.npm
$ rm -rf ~/{local,lib,include,node*,npm,.npm*}

Next, re-install node with nvm.

--

--