Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

Homebrew installed npm can't upgrade itself #22408

Closed
deiga opened this issue Sep 9, 2013 · 33 comments
Closed

Homebrew installed npm can't upgrade itself #22408

deiga opened this issue Sep 9, 2013 · 33 comments

Comments

@deiga
Copy link
Contributor

deiga commented Sep 9, 2013

Here's the issue on npm https://github.com/isaacs/npm/issues/3794

This should be fixed in the way Homebrew handles npm

@MikeMcQuaid
Copy link
Member

This issue isn't helpful; there's basically no information here for how we'd actually fix this.

@thewalkingtoast
Copy link
Contributor

The symlink that Homebrew creates causes a conflict with how npm wants to upgrade itself when an upgrade to npm is availabe:

For instance:

$ brew install node
.....
$ npm update -g
npm http GET https://registry.npmjs.org/npm
npm http 304 https://registry.npmjs.org/npm
npm http GET https://registry.npmjs.org/npm/1.3.11
npm http 304 https://registry.npmjs.org/npm/1.3.11
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.18/lib/node_modules/npm/lib/utils/gently-rm.js:41:12)
npm ERR! error rolling back     at next (/usr/local/Cellar/node/0.10.18/lib/node_modules/npm/lib/utils/gently-rm.js:27:14)
npm ERR! error rolling back     at /usr/local/Cellar/node/0.10.18/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  [email protected] { [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.

npm ERR! System Darwin 12.5.0
npm ERR! command "/usr/local/Cellar/node/0.10.18/bin/node" "/usr/local/bin/npm" "update" "-g"
npm ERR! cwd /Users/Adam
npm ERR! node -v v0.10.18
npm ERR! npm -v 1.3.8
npm ERR! path /usr/local/bin/npm
npm ERR! code EEXIST
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/Adam/npm-debug.log
npm ERR! not ok code 0

To fix it, change the formula's symlink to be

/usr/local/bin/npm -> ../lib/node_modules/npm/bin/npm-cli.js

instead of

/usr/local/bin/npm -> ../Cellar/node/<VERSION>/lib/node_modules/npm/bin/npm-cli.js

@jacknagel
Copy link
Contributor

This issue is that the way the prepackaged npm is installed by the node build system is fundamentally incompatible with how Homebrew manages its own packages symlinks.

@thewalkingtoast
Copy link
Contributor

Ah I see. That makes sense. No simple solution then besides manually changing the symlink.

@oskarrough
Copy link

@aradabaugh could you help manually change the symlink? Not sure how to proceed.

@thewalkingtoast
Copy link
Contributor

@oskarrough Sure. /usr/local/bin/npm should be a symlink to the Cellar version. Remove it and symlink the npm installed npm update:

$ rm /usr/local/bin/npm
$ ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm

@deiga
Copy link
Contributor Author

deiga commented Sep 26, 2013

@aradabaugh Couldn't those lines just be added to the brew formula for node?

@thewalkingtoast
Copy link
Contributor

Probably not from Homebrew's perspective. As @jacknagel commented, Homebrew likes to manage everything under the Cellar and npm stores it's updates outside that in /usr/local/lib. I suppose npm is just the exception here.

@jacknagel
Copy link
Contributor

I know this is annoying. I want it to just work. But I need to think through potential ramifications before committing to a fix.

@deiga
Copy link
Contributor Author

deiga commented Sep 29, 2013

Yeah, I just noticed that by symlinking npm then the upgrade of node fails unless --without-npm is specified

@ptrhvns
Copy link

ptrhvns commented Oct 24, 2013

Is there any update on this issue? Thanks.

@StevenACoffman
Copy link

How about adding a caveat for aradabaugh's workaround?

$ rm /usr/local/bin/npm
$ ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm

@zimme
Copy link

zimme commented Nov 21, 2013

How about symlinking /usr/local/bin/npm to /usr/local/lib/node_modules/npm/bin/npm-cli.js and make sure homebrews upgrade of node don't upgrades npm (--without-npm)? I believe the composer package only installs composer and lets composer upgrade it self instead of upgrading via homebrew.

@StevenACoffman
Copy link

aradabaugh's workaround still resulted in some error messages when I attempted to update.
I had to brew remove node
brew install node --without-npm
#install npm seperately from brew's node
curl https://npmjs.org/install.sh | sh
There should be a caveat about this or whatever the preferred solution is.

@janv
Copy link
Contributor

janv commented Nov 21, 2013

Package managers managing package managers rarely works out well.
See also rubygems on debian.

I recommend using a language specific tool, I switched to installing node through nvm and ruby through rbenv.
Both is pretty straightforward.

@thewalkingtoast
Copy link
Contributor

Something has changed since I posted my workaround; StevenACoffman's
description is accurate of my current situation with this. I haven't had
time to find a new workaround but I like zimme's idea.

On Thu, Nov 21, 2013 at 6:00 AM, Jan Varwig [email protected]:

Package managers managing package managers rarely works out well.
See also rubygems on debian.

I recommend using a language specific tool, I switched to installing node
through nvm https://github.com/creationix/nvm and ruby through rbenvhttps://github.com/sstephenson/rbenv
.
Both is pretty straightforward.


Reply to this email directly or view it on GitHubhttps://github.com//issues/22408#issuecomment-28986117
.

@gabrielstuff
Copy link

Yup, I can confirm that homebrew update, and system up to date, this issue still exist and should be open.
This little tricks allowed me to update : https://github.com/isaacs/npm/issues/3794#issuecomment-30338627

npm update -gf

@mgol
Copy link

mgol commented Dec 18, 2013

The proposed workaround has stopped working with the newest node. I'm on OS X 10.9.1 with node 0.10.23. After updating to the newest node I can't do npm -g update since I get an error like mentioned in this bug report. However, if I invoke:

$ rm /usr/local/bin/npm
$ ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm

and then do npm -g update, I get this:

npm ERR! error rolling back Error: Refusing to delete: /usr/local/share/man/man1/npm-README.1 not in /usr/local/lib/node_modules/npm
npm ERR! error rolling back     at clobberFail (/usr/local/Cellar/node/0.10.23/lib/node_modules/npm/lib/utils/gently-rm.js:41:12)
npm ERR! error rolling back     at next (/usr/local/Cellar/node/0.10.23/lib/node_modules/npm/lib/utils/gently-rm.js:27:14)
npm ERR! error rolling back     at /usr/local/Cellar/node/0.10.23/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  [email protected] { [Error: Refusing to delete: /usr/local/share/man/man1/npm-README.1 not in /usr/local/lib/node_modules/npm]
npm ERR! error rolling back   code: 'EEXIST',
npm ERR! error rolling back   path: '/usr/local/share/man/man1/npm-README.1' }
npm ERR! Refusing to delete: /usr/local/share/man/man1/npm-README.1 not in /usr/local/lib/node_modules/npm
File exists: /usr/local/share/man/man1/npm-README.1
Move it away, and try again. 

So for now I'm unable to do npm -g update with node from Homebrew.

@mgol
Copy link

mgol commented Dec 18, 2013

For now I'm using the following script to update all global packages except npm. I'd love to update npm too, though.

npm -g list --depth 0 | grep -v "^/" | cut -f2 -d" " | cut -f1 -d@ | grep -v "^npm$" | xargs npm -g update

@chulkilee
Copy link
Contributor

Once all files for npm package are symlinks from node module, it can be updated.

#!/bin/bash

for man in 1 3 5 7; do
  ln -sf /usr/local/lib/node_modules/npm/man/man${man}/* /usr/local/share/man/man${man}
done

ln -sf /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm

npm update npm -g

It may be better to do the symlink fix at homebrew formula.

@mgol
Copy link

mgol commented Dec 18, 2013

@chulkilee Thanks for the script, it works. :)

@janraasch
Copy link

@chulkilee saved my day. Thanks.

@trippingtarballs
Copy link

+1 @chulkilee -- Thanks for the script. Spent ages trying to sort this.

@jarrodldavis
Copy link

I'm not sure about others, but the script from @chulkilee broke my install. I kept getting Error: Cannot find module 'editor'. I had to uninstall and reinstall it, then patch things up with brew doctor.

@gmaghera
Copy link

I've just run into this issue myself. It baffles that this issue was closed to due there not being any information on how to fix this issue, @MikeMcQuaid. Isn't it sufficient to describe symptoms and steps to reproduce when opening an issue? Please fix this, if possible.

@MikeMcQuaid
Copy link
Member

As @jacknagel said already:

This issue is that the way the prepackaged npm is installed by the node build system is fundamentally incompatible with how Homebrew manages its own packages symlinks.

The above needs to be fixed by upstream or someone knowledgable enough to make a pull request.

@jacknagel
Copy link
Contributor

To provide a little more detail, the way npm determines what files belong to a package and resolves symlinks seems to get confused by the symlink Homebrew makes from /usr/local/bin/npm to /usr/local/Cellar/node/<version>/bin/npm (a similar thing happens to the npm man pages). If that can be overcome then we can make this work.

@moeffju
Copy link

moeffju commented Feb 28, 2014

I second @janv’s suggestion of just using nvm – which you can, in turn, install via homebrew.

brew install nvm
nvm install 0.11

and you’re done.

@mgol
Copy link

mgol commented Mar 11, 2014

@jarrodldavis I restorted to:

  1. First installing node normally: brew install node
  2. Then running the script by @chulkilee.
  3. Finally, setting up an alias:
alias brewuu='brew update && {brew upgrade node --without-npm; brew upgrade}'

In this way, node doesn't update npm with itself so it doesn't cause these conflicts. When I want to update npm, I just do npm -g update and update it along with other packages. Works fine so far.

@deiga
Copy link
Contributor Author

deiga commented Mar 11, 2014

I definitely support @moeffju suggestion, handling package managers with package managers has always been tricky, nvm is a clean and handy solution

@karol-f
Copy link

karol-f commented Sep 10, 2014

@chulkilee thanks!

@ijy
Copy link

ijy commented Sep 24, 2014

Just to close off this issue, as of 02 April 2014 npm is now installed using a tarball so it is installed by Homebrew when installing Node.js but it is free to manage and upgrade itself. None of the above workarounds should be necessary.

You just need brew install node and you're done.

@jpdevries
Copy link

thanks @chulkilee this worked for me too #22408 (comment)

@Homebrew Homebrew locked and limited conversation to collaborators Dec 13, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests