[Node.js] How to Install npm on Mac

Tadashi Shigeoka ·  Mon, October 29, 2012

This guide shows you how to install npm, the Node.js package management tool, on Mac OS X Mountain Lion.

This assumes that Node.js has been pre-installed using nodebrew.

[Node.js] How to Install the Version Management Tool nodebrew on Mac

% curl 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   3979      0  0:00:01  0:00:01 --:--:--  7400
tar=/usr/bin/tar
version:
bsdtar 2.8.3 - libarchive 2.8.3
install [email protected]
fetching: http://registry.npmjs.org/npm/-/npm-1.1.65.tgz
0.6.21-pre
1.1.65
cleanup prefix=/Users/your_username/.nodebrew/current

All clean!
/Users/your_username/.nodebrew/current/bin/npm -> /Users/your_username/.nodebrew/current/lib/node_modules/npm/bin/npm-cli.js
[email protected] /Users/your_username/.nodebrew/current/lib/node_modules/npm
It worked

Verify that npm was installed correctly.

% npm --version
1.1.65

To uninstall npm, simply run the following command.

% sudo npm uninstall npm -g

By the way, please note that the URL seems to have changed from http to https.

If you try to install with http, you’ll get an error like this:

% curl http://npmjs.org/install.sh | sudo sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    85    0    85    0     0     75      0 --:--:--  0:00:01 --:--:--   352
sh: line 1: syntax error near unexpected token `newline'
sh: line 1: `Moved: https://npmjs.org/install.sh'

That’s all from the Gemba.