Trouble installing npm

I got a clean install on my mac book pro with mountain lion. Then have installed nodejs with homebrew i.e. brew install nodejs, but now I cant get npm to install. eg.

    $ node -v
    v0.8.6
    $ curl -k https://npmjs.org/install.sh | sudo sh
    % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  7882  100  7882    0     0  11359      0 --:--:-- --:--:-- --:--:-- 13803

Then nothing else happens. NPM is not installed.

Homebrew does not currently install NPM with Node, per https://github.com/mxcl/homebrew/blob/6925f69e/Library/Formula/node.rb#L25-26:

def install
  # Why skip npm install? Read https://github.com/mxcl/homebrew/pull/8784.
  args = ["--prefix=#{prefix}", "--without-npm"]

  ...

  system "./configure", *args
  system "make install"
end

As promised by the formula, you can read more details at https://github.com/mxcl/homebrew/pull/8784, and a recent pull request (last updated just 9 hours ago), has even more discussion.

I personally prefer installing from source using NVM instead of Homebrew; the first half of my Node.js First Steps details installing Node via this method.

It's worth noting that, starting in Node v0.8.6, you can download precompiled binaries for some distributions, including OS X. Just click the download link at the http://nodejs.org and then click "Other release files"; from there, you can download the Darwin 32- or 64-bit binaries and extract them into someplace on your PATH.

Try it without sudo:

$ curl https://npmjs.org/install.sh | sh

The main point of brew is that it installs things where you don't need root-level access, and npm's installer is designed to follow the Node installation's lead.

Press enter, and then you see this:

Sorry, try again.
Password:

put your password and work.

npm@1.1.71 /usr/local/lib/node_modules/npm
It worked