How to install npm for node.js installed with homebrew installed at custom path?

eonil picture eonil · Nov 29, 2011 · Viewed 9.3k times · Source

I'm using Mac OS X Lion 10.7, and installed homebrew with alternate install at custom path to keep it user scope requiring no sudo. I installed node.js successfully. But npm is not being installed.

Last login: Tue Nov 29 10:26:51 on ttys003
Hoons-MacBook-Air:~ Eonil$ node --version
v0.6.2
Hoons-MacBook-Air:~ Eonil$ node
> 
(^C again to quit)
> Hoons-MacBook-Air:~ Eonil$ curl http://npmjs.org/install.sh | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  7184  100  7184    0     0   4581      0  0:00:01  0:00:01 --:--:-- 19363
npm cannot be installed without nodejs.
Install node first, and then try again.

Maybe node is installed, but not in the PATH?
Note that running as sudo can change envs.

PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:~/Unix/homebrew/bin
Hoons-MacBook-Air:~ Eonil$ ls ~/Unix/homebrew/bin/
brew        node        node-waf
Hoons-MacBook-Air:~ Eonil$ 

I see the path to the binary to node is added to $PATH variable. I don't know why npm complains. How can I make it to be installed?

Answer

eonil picture eonil · Nov 29, 2011

I got the answer from Stackoverlow/Unix & Linux site.

https://unix.stackexchange.com/questions/25605/how-to-add-home-directory-path-to-be-discovered-by-unix-which-command

The core problem was the system doesn't expand ~ home directory symbol. So I had to put the absolute directory using $HOME environment variable.