2

I'm trying to install nodejs on mac using homebrew, but when I run the command:

brew install node

I get the following error:

Beginning with 0.8.0, this recipe now comes with npm.
It appears you already have npm installed at /usr/local/lib/node_modules/npm.
To use the npm that comes with this recipe, first uninstall npm with
`npm uninstall npm -g`, then run this command again.

If you would like to keep your installation of npm instead of
using the one provided with homebrew, install the formula with
the `--without-npm` option.

but when I run:

sudo npm uninstall npm -g

I get:

sudo: npm: command not found

When I run the command npm, I get:

-bash: /usr/local/bin/npm: No such file or directory

so I'm not sure whether it's actually installed or not.

My node version is 0.8.22 (I have no idea where it came from). How should I update it to the latest version?

  • If you use homebrew just use it and nothing else. I would try to uninstall using brew first. Also did yiu install node via home-brew? – user151019 Jun 14 '13 at 13:22
  • If brew list shows both node and npm, just delete both and start again? – bmike Jan 25 '14 at 22:30
  • I don't have enough understanding of this thread on homebrew on how npm became broken when installed, but it might help you with some documented workarounds like the One-line npm install npm_config_prefix=/usr/local/lib/node_modules; curl -sSL https://npmjs.org/install.sh | bash – bmike Mar 22 '14 at 12:16
1

Is /usr/local/bin/npm a broken symlink? That would make sudo npm print an error like command not found and npm print an error like No such file or directory.

You could try creating a new symlink for node:

$ rm /usr/local/bin/npm; brew unlink node; brew link node
Unlinking /usr/local/Cellar/node/0.10.5... 4 links removed
Linking /usr/local/Cellar/node/0.10.5... 5 symlinks created
$ sudo /usr/local/bin/npm uninstall npm -g

Or use /usr/local/opt/node/bin/npm:

$ ls -l `brew --prefix node`
lrwxr-xr-x  1 lauri  admin  21 Jun 14 18:27 /usr/local/opt/node -> ../Cellar/node/0.10.5
$ sudo /usr/local/opt/node/bin/npm uninstall npm -g

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .