Homebrew installed npm can't upgrade itself #22408

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

Projects

None yet
@deiga
Contributor
deiga commented Sep 9, 2013

Here's the issue on npm npm/npm#3794

This should be fixed in the way Homebrew handles npm

@MikeMcQuaid
Member

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

@MikeMcQuaid MikeMcQuaid closed this Sep 9, 2013
@thewalkingtoast
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  npm@1.3.11 { [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
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
Contributor

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

@oskarrough

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

@thewalkingtoast
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
Contributor
deiga commented Sep 26, 2013

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

@thewalkingtoast
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
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
Contributor
deiga commented Sep 29, 2013

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

@Tekhne
Tekhne commented Oct 24, 2013

Is there any update on this issue? Thanks.

@StevenACoffman

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

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
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
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 notifications@github.comwrote:

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/mxcl/homebrew/issues/22408#issuecomment-28986117
.

@gabrielstuff

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 : npm/npm#3794 (comment)

npm update -gf

@mgol
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  npm@1.3.21 { [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
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
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
mgol commented Dec 18, 2013

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

@MattCowski MattCowski referenced this issue in angular-fullstack/generator-angular-fullstack Jan 21, 2014
Closed

1.1.1 is the current latest version in npm #48

@janraasch

@chulkilee saved my day. Thanks.

@rbose85
rbose85 commented Jan 24, 2014

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

@jarrodldavis

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

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
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
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
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
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
Contributor
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
karol-f commented Sep 10, 2014

@chulkilee thanks!

@ijy
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.

@claui claui added a commit to claui/homebrew that referenced this issue Nov 24, 2014
@claui claui node: Remove outdated caveat as of #22408 64a4f4c
@BrewTestBot BrewTestBot added a commit to BrewTestBot/homebrew that referenced this issue Nov 24, 2014
@claui @BrewTestBot claui + BrewTestBot node: Remove outdated caveat as of #22408 2ff7453
@claui claui added a commit to claui/homebrew that referenced this issue Nov 25, 2014
@claui claui node: Rephrase caveat to clarify post-#22408 situation 893e7e9
@BrewTestBot BrewTestBot added a commit to BrewTestBot/homebrew that referenced this issue Nov 25, 2014
@claui @BrewTestBot claui + BrewTestBot node: Rephrase caveat to clarify post-#22408 situation 3d23fec
@MikeMcQuaid MikeMcQuaid added a commit that referenced this issue Nov 25, 2014
@claui @MikeMcQuaid claui + MikeMcQuaid node: Rephrase caveat to clarify post-#22408 situation
Closes #34413.

Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
4b9395f
@jpdevries

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

@DomT4 DomT4 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.