Skip to content
This repository has been archived by the owner. It is now read-only.

Error: Refusing to delete: /usr/local/bin/npm #3794

Closed
bdielman opened this issue Aug 15, 2013 · 97 comments
Closed

Error: Refusing to delete: /usr/local/bin/npm #3794

bdielman opened this issue Aug 15, 2013 · 97 comments
Labels

Comments

@bdielman
Copy link

@bdielman bdielman commented Aug 15, 2013

I installed Node via Homebrew after a reinstall of my OS. Trying to run npm update -g and getting the following error which I've never come across before.

npm ERR! error rolling back Error: Refusing to delete: /usr/local/bin/npm not in /usr/local/lib/node_modules/npm
npm ERR! error rolling back     at clobberFail (/usr/local/Cellar/node/0.10.15/lib/node_modules/npm/lib/utils/gently-rm.js:41:12)
npm ERR! error rolling back     at next (/usr/local/Cellar/node/0.10.15/lib/node_modules/npm/lib/utils/gently-rm.js:27:14)
npm ERR! error rolling back     at /usr/local/Cellar/node/0.10.15/lib/node_modules/npm/lib/utils/gently-rm.js:36:12
npm ERR! error rolling back     at Object.oncomplete (fs.js:107:15)
npm ERR! error rolling back  npm@1.3.7 { [Error: Refusing to delete: /usr/local/bin/npm not in /usr/local/lib/node_modules/npm] code: 'EEXIST', path: '/usr/local/bin/npm' }
npm ERR! Refusing to delete: /usr/local/bin/npm not in /usr/local/lib/node_modules/npm
File exists: /usr/local/bin/npm
Move it away, and try again.

On Node v0.10.15 and npm v1.3.5.

@Ashot-KR
Copy link

@Ashot-KR Ashot-KR commented Aug 23, 2013

got same error

@rainder
Copy link

@rainder rainder commented Aug 25, 2013

same issue

@markson
Copy link

@markson markson commented Aug 26, 2013

same here

@isaacs
Copy link
Member

@isaacs isaacs commented Aug 26, 2013

  1. Uninstall the node and npm homebrew packages.
  2. Go to http://nodejs.org/ and click the big green button.
  3. Run the downloaded pkg, and follow the prompts.
  4. Now everything works as intended.
@isaacs isaacs closed this Aug 26, 2013
@nikolay
Copy link

@nikolay nikolay commented Sep 5, 2013

@isaacs Homebrew is a pretty popular package manager with many benefits and you should not ignore it. You can't advise people not to use it! Can you at least skip self-update under Homebrew? Nobody really cares if they are using the latest and greatest npm, but do care about other packages.

@luk-
Copy link
Contributor

@luk- luk- commented Sep 6, 2013

@nikolay

Having npm be skipped on updates is not something we can do, as it would change an expected semantic of npm for a single package. This is confusing for users, and sends us (contributors and maintainers) down a path of unreasonable functionality/code maintenance.

However, if this issue is major pain point for a lot of people, perhaps we can check with the homebrew folks if there's a way for them to handle the npm install differently. I'm not sure if this is possible with how and where homebrew installs things, but that doesn't mean it's not worth a try. Should there be a solution from this angle, it would be a long-term solution instead of a quick fix that will introduce technical debt.

@nikolay
Copy link

@nikolay nikolay commented Sep 6, 2013

@luk- Now thinking about it, I have to agree with you - maybe fixing it in Homebrew would be best. Let me look into their "formula" and I will get back to you!

@nikolay
Copy link

@nikolay nikolay commented Sep 6, 2013

@luk- Yes, they can definitely fix it on their end by changing a symlink. I will try submitting a patch.

@MikeMcQuaid
Copy link

@MikeMcQuaid MikeMcQuaid commented Sep 9, 2013

Homebrew dev here: if you want to submit an issue to us about this please clarify what the expected behaviour is, what the actual behaviour is and (ideally) submit a pull request with the actual fix.

@nikolay
Copy link

@nikolay nikolay commented Sep 9, 2013

@MikeMcQuaid I will submit the patch tonight or tomorrow. I will provide all the required info. Thanks!

@mysterycommand
Copy link

@mysterycommand mysterycommand commented Oct 27, 2013

2 months ago? What happened?

@robsonpeixoto
Copy link

@robsonpeixoto robsonpeixoto commented Oct 27, 2013

News? I'm having this problem.

@moollaza
Copy link

@moollaza moollaza commented Oct 28, 2013

me too...

@MikeMcQuaid
Copy link

@MikeMcQuaid MikeMcQuaid commented Oct 28, 2013

There isn't any news. If you want this fixed I suggest trying to write the patch yourself.

@MoOx
Copy link

@MoOx MoOx commented Oct 28, 2013

It's a shame :(

@ryanburnett
Copy link

@ryanburnett ryanburnett commented Oct 28, 2013

I had the same issue.

Since there's still no fix I followed isaacs' advice and uninstalled the node and npm homebrew packages and used the nodejs.org installer. Working great now.

@moollaza
Copy link

@moollaza moollaza commented Oct 28, 2013

@ryanburnett Yup, I did the same -- everything is good now :)

@kvervo
Copy link

@kvervo kvervo commented Oct 31, 2013

If you do not want to uninstall node from brew.

To workaround this issue, update symbolic link to npm as npm itself expects:
$ rm /usr/local/bin/npm
$ cd /usr/local/bin && ln -s ../lib/node_modules/npm/bin/npm-cli.js npm

Reference: Homebrew/legacy-homebrew#22408

@twome
Copy link

@twome twome commented Nov 2, 2013

Thanks @kvervo. It'd be lovely if npm worked with homebrew. God, I wish there was a universal package manager that dependably worked for every major platform such as this.

@elgs
Copy link

@elgs elgs commented Nov 4, 2013

sudo npm update -gf

Interesting thing. I thought the f denotes force, however, the f is not documented in npm help update, but it works here.

@giacecco
Copy link

@giacecco giacecco commented Dec 9, 2013

-gf worked here as well. sudo shouldn't be necessary as I believe homebrew should be installed to work nicely without requiring it.

@chevtek
Copy link
Contributor

@chevtek chevtek commented Dec 9, 2013

Brew doesn't require sudo but npm occasionally does when it pukes.

@gabrielstuff
Copy link

@gabrielstuff gabrielstuff commented Dec 11, 2013

I confirm npm update -gf fix this error. No idea how to patch homebrew to make it work... hope someone will do it.

@paulxtiseo
Copy link

@paulxtiseo paulxtiseo commented Dec 19, 2013

After forcing the overwrite by via the -gf switch, you can re-establish the links by calling:
brew unlink node && brew link --overwrite node

@kud
Copy link

@kud kud commented Jan 29, 2014

This issue simply makes me sad.

@anthonybrown
Copy link

@anthonybrown anthonybrown commented Feb 19, 2014

@kud me too, I don't want to uninstall my node and npm with brew, no fix for this?

@kud
Copy link

@kud kud commented Feb 19, 2014

For the moment, I do $ npm install -g --silent but ain't the best idea. :D

@elgs
Copy link

@elgs elgs commented Feb 19, 2014

My ultimate way to install node/npm with homebrew

$ brew install node --without-npm
$ curl -L https://npmjs.org/install.sh | sh

Please note sudo is NOT used anywhere in the above commands. The reason why I want to install node and npm separately is that homebrew does not like npm to update npm iteslf. homebrew has a philosophy that everything is inside it's Cellar. I personally appreeciate homebrew's clean way of doing things. However npm is just yet another package manager, which is not aware of homebrew's cellars philosophy. Therefore, I prefer to get homebrew to manager node, and let npm manage itself.

@rbrisita
Copy link

@rbrisita rbrisita commented Mar 31, 2014

Anyone having this issue with Snow Leopard, these are my steps to fix:

$ sudo chown -R $USER /usr/local
$ brew install node --without-npm
$ curl -L https://npmjs.org/install.sh | sh
@ripter
Copy link

@ripter ripter commented Apr 2, 2014

npm needs to work with homebrew. I should be able to run npm update -g and have it update all of my global packages correctly without error. If I wanted to update node/npm I would use brew update node.

Node pretty much requires npm at this point. Telling people to not use homebrew for npm is ridiculous. Homebrew is used on a lot of production systems and ignoring it is a mistake.

@kud
Copy link

@kud kud commented Apr 2, 2014

lol no. now unsubscribed

@chevtek
Copy link
Contributor

@chevtek chevtek commented Apr 2, 2014

@ripter you need to see this PR thread.

@elgs
Copy link

@elgs elgs commented Apr 2, 2014

@ripter the reason that I love homebrew is that homebrew helps to manage the upgrade of all my brewed software with a single command. Now npm can upgrade itself by npm update npm -g, for me npm can live without homebrew in my computer. I understand ideally when homebrew upgrades node, it upgrades npm. However, the reality is that npm is not happy when it found that homebrew had upgraded npm when npm tries to upgrade itself.

Telling people to not use homebrew for npm is not telling people to not use npm with node. I agreed, npm is pretty much a must for node.

@ripter
Copy link

@ripter ripter commented Apr 2, 2014

@chevex The issue is that npm update -g should NOT update npm. npm update updates the packages, not npm. It's this overloaded functionality that causes the issue.

npm help update doesn't even mention that it will update npm. It just says it will update the packages.

What happens if I need to pin the version of npm but I want to update the global packages for a production environment?

@chevtek
Copy link
Contributor

@chevtek chevtek commented Apr 2, 2014

@ripter Good luck getting very many people to agree that npm shouldn't update npm. That pull request already has a working solution that allows homebrew to install both node and npm, then let's npm update itself thereafter. It's fine now; go test out the fix for yourself. You're not going to convince the maintainers to stop npm from updating itself; that's a far more drastic change than manipulating the brew formula as has already been done.

@ripter
Copy link

@ripter ripter commented Apr 2, 2014

@chevex npm can update npm. That's fine. npm update -g should not update npm. It should do exactly what the help says:

"This command will update all the packages listed to the latest version (specified by the tag config)."

I understand that npm might see itself as a package. But that's not the expectation. This entire issue could be resolved by adding something like npm upgrade

@chevtek
Copy link
Contributor

@chevtek chevtek commented Apr 2, 2014

That doesn't really fix anything. It just makes it so npm breaks less often since it won't break with npm update -g. It would still break with npm update npm, so it's not actually a fix now is it? If anything, they should just update the documentation to better reflect what it does.

@ripter
Copy link

@ripter ripter commented Apr 2, 2014

npm update npm is explicit. So it does solve the issue. Homebrew users simply wouldn't run this command.

The issue is that npm tries to update itself when updating all global packages. aka npm update -g
This behavior is not documented and as far as I know there is no way to to update the global packages without updating npm.

@chevtek
Copy link
Contributor

@chevtek chevtek commented Apr 2, 2014

As @MikeMcQuaid says in his own PR:

Install npm to the expected location using the upstream tarball. This should make everyone happier.

This means Homebrew doesn't really manage npm any more but does install it. This is treated similarly to how we handle pip and means that npm can upgrade itself.

So no, leaving npm users to get frustrated when they try npm update npm and it totally breaks their install, is not a fix. Telling people "just don't type that command" and calling it a fix is like the doctor saying "well just don't move your arm that way" and calling it a cure for shoulder pain. Letting homebrew handle npm the exact same way it handles something like pip makes way more sense.

@ripter
Copy link

@ripter ripter commented Apr 2, 2014

@chevex I never said to leave npm users frustrated when they try npm update npm. That should update npm. That command explicitly says to update npm.

I'm saying npm update -g should not update npm. The command is to update packages not the package manager.

This issue isn't just homebrew. This issue makes it impossible to update all global packages without updating npm. As it stands now, a production environment requires someone to manually add an npm update xyz command for every package if you want to pin the npm version.

@chevtek
Copy link
Contributor

@chevtek chevtek commented Apr 2, 2014

If you install npm via homebrew with the old formula then trying to update npm via npm WILL break npm. Changing the behavior of npm will not fix this; the change has to happen in homebrew (even in your "fix" homebrew formula still has to change as well). I don't understand why you're arguing with me. There is already a working fix and it will be rolled into the production version of homebrew before you know it. This problem is solved, solution just has to ship.

@ripter
Copy link

@ripter ripter commented Apr 2, 2014

if npm update -g is used only to update packages (not npm), which is what the documentation says it does, then most Hombrew users wouldn't know the issue exists. Homebrew users wouldn't try to use npm to update npm. They would simply use Homebrew.

The issue is that npm overloaded npm update -g to update npm along with all the packages. Which means you can't pin npm to a specific version and you get the error when something else tries to manage npm's version.

@chevtek
Copy link
Contributor

@chevtek chevtek commented Apr 2, 2014

lol no. now unsubscribed as well

@kud
Copy link

@kud kud commented Apr 2, 2014

Hahaha @chevex it was premeditated. ;) People who don't want to listen won't change their mind.

@MikeMcQuaid
Copy link

@MikeMcQuaid MikeMcQuaid commented Apr 2, 2014

@chevex @ripter Let's stop arguing about something which will not be a problem for much longer.

@MikeMcQuaid
Copy link

@MikeMcQuaid MikeMcQuaid commented Apr 4, 2014

This is (finally) fixed in Homebrew/legacy-homebrew@f900829.

@rjhilgefort
Copy link

@rjhilgefort rjhilgefort commented Apr 7, 2014

👍

@anthonybrown
Copy link

@anthonybrown anthonybrown commented Jul 21, 2014

@MikeMcQuaid you mean npm is no longer installed with brew install node, so there is no need to install with brew install node --without-npm?

@chevtek
Copy link
Contributor

@chevtek chevtek commented Jul 21, 2014

No it is, just after the initial install npm is allowed to manage itself going forward. If you don't want it to install npm at all, still use --without-npm.

@MikeMcQuaid
Copy link

@MikeMcQuaid MikeMcQuaid commented Jul 21, 2014

@anthonybrown It's installed in the correct location using the npm tarball now.

@surfer190
Copy link

@surfer190 surfer190 commented Apr 18, 2016

Just do this:

brew uninstall node

Then install from node website

@andlef
Copy link

@andlef andlef commented Oct 25, 2016

ln -s /Applications/Atom.app/Contents/Resources/app/apm/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm

@ghost
Copy link

@ghost ghost commented Dec 19, 2016

Does anyone have an explanation for this warning in the screenshot it seems to pertain this thread:
screen shot 2016-12-18 at 8 10 37 pm

@varjmes
Copy link

@varjmes varjmes commented Dec 19, 2016

@adsr13 this appears to be completely unrelated to this issue. It is to do with the ember-cli tool, not npm.

It can be ignored. It's telling you that they can't guarantee that ember-cli will work with Node v6.9.2. But if everything is going well, then you have nothing to worry about.

Any further issues, please open a new Issue in the tracker! :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
You can’t perform that action at this time.