How to update nodejs on mac? 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?
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 -&gt; ../Cellar/node/0.10.5
$ sudo /usr/local/opt/node/bin/npm uninstall npm -g