Skip to content
This repository has been archived by the owner. 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 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

@MikeMcQuaid MikeMcQuaid commented Sep 9, 2013

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
Copy link
Contributor

@thewalkingtoast thewalkingtoast commented Sep 19, 2013

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
Copy link
Contributor

@jacknagel jacknagel commented Sep 19, 2013

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

@thewalkingtoast thewalkingtoast commented Sep 19, 2013

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

@oskarrough
Copy link

@oskarrough oskarrough commented Sep 26, 2013

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

@thewalkingtoast
Copy link
Contributor

@thewalkingtoast thewalkingtoast commented Sep 26, 2013

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

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

@thewalkingtoast
Copy link
Contributor

@thewalkingtoast thewalkingtoast commented Sep 26, 2013

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

@jacknagel jacknagel commented Sep 26, 2013

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 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 ptrhvns commented Oct 24, 2013

Is there any update on this issue? Thanks.

@StevenACoffman
Copy link

@StevenACoffman StevenACoffman commented Nov 8, 2013

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

@StevenACoffman StevenACoffman commented Nov 21, 2013

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

@thewalkingtoast thewalkingtoast commented Nov 21, 2013

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

@gabrielstuff
Copy link

@gabrielstuff gabrielstuff commented Dec 11, 2013

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

@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
Copy link
Contributor

@chulkilee chulkilee commented Dec 18, 2013

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 mgol commented Dec 18, 2013

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

@janraasch
Copy link

@janraasch janraasch commented Jan 22, 2014

@chulkilee saved my day. Thanks.

@trippingtarballs
Copy link

@trippingtarballs trippingtarballs commented Jan 24, 2014

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

@jarrodldavis
Copy link

@jarrodldavis jarrodldavis commented Feb 18, 2014

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

@gmaghera gmaghera commented Feb 24, 2014

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

@MikeMcQuaid MikeMcQuaid commented Feb 25, 2014

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

@jacknagel jacknagel commented Feb 25, 2014

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

@chulkilee thanks!

@ijy
Copy link

@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 added a commit to claui/homebrew that referenced this issue Nov 24, 2014
claui added a commit to claui/homebrew that referenced this issue Nov 25, 2014
MikeMcQuaid added a commit that referenced this issue Nov 25, 2014
Closes #34413.

Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
@DomT4 DomT4 mentioned this issue Jan 23, 2015
@jpdevries
Copy link

@jpdevries jpdevries commented Dec 13, 2015

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
Linked pull requests

Successfully merging a pull request may close this issue.

None yet