node.jsのアップデート

node.jsの書籍を購入したので、久しぶりに触ってみようかと思ったら、記載されているものと違う動きになって、ちゃんと動かなかったのでまとめておく。
環境はOS X Lionです。
インストール時の記事は以下。
node.jsを試してみた - ZeBeVogue別館
最初に出たのが以下のエラー。npm installでエラーが起きました。

$ npm install
npm ERR! error installing express@3.0.0beta4 Error: Unsupported
npm ERR! error installing express@3.0.0beta4     at checkEngine (/usr/local/lib/node_modules/npm/lib/install.js:493:14)
npm ERR! error installing express@3.0.0beta4     at Array.0 (/usr/local/lib/node_modules/npm/node_modules/slide/lib/bind-actor.js:15:8)
npm ERR! error installing express@3.0.0beta4     at LOOP (/usr/local/lib/node_modules/npm/node_modules/slide/lib/chain.js:15:13)
npm ERR! error installing express@3.0.0beta4     at chain (/usr/local/lib/node_modules/npm/node_modules/slide/lib/chain.js:20:4)
npm ERR! error installing express@3.0.0beta4     at installOne_ (/usr/local/lib/node_modules/npm/lib/install.js:471:3)
npm ERR! error installing express@3.0.0beta4     at installOne (/usr/local/lib/node_modules/npm/lib/install.js:411:3)
npm ERR! error installing express@3.0.0beta4     at /usr/local/lib/node_modules/npm/lib/install.js:347:9
npm ERR! error installing express@3.0.0beta4     at /usr/local/lib/node_modules/npm/node_modules/slide/lib/async-map.js:54:35
npm ERR! error installing express@3.0.0beta4     at Array.forEach (native)
npm ERR! error installing express@3.0.0beta4     at /usr/local/lib/node_modules/npm/node_modules/slide/lib/async-map.js:54:11
npm ERR! error rolling back express@3.0.0beta4 Error: ENOTEMPTY, Directory not empty '/Users/******/Sites/webdbsample/node_modules/express'
npm ERR! Unsupported
npm ERR! Not compatible with your version of node/npm: connect@2.3.4
npm ERR! Required: {"node":">= 0.5.0"}
npm ERR! Actual:   {"npm":"1.0.101","node":"0.4.12"}
npm ERR! 
npm ERR! System Darwin 11.4.0
npm ERR! command "node" "/usr/local/bin/npm" "install"
npm ERR! cwd /Users/*****/Sites/webdbsample
npm ERR! node -v v0.4.12
npm ERR! npm -v 1.0.101
npm ERR! code ENOTSUP
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/****/Sites/webdbsample/npm-debug.log
npm not ok

Required: {"node":">= 0.5.0"}とあるので、nodeのバージョンが古いようです。という事で確認してみます。

$ node -v
v0.4.12

インストールした時のままです。Homebrewでインストールしたので、アップグレードします。

$ brew update
...
$ brew upgrade node
==> Upgrading node
==> Downloading http://nodejs.org/dist/v0.8.0/node-v0.8.0.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/node/0.8.0 --without-npm
==> make install
==> Caveats
Homebrew has NOT installed npm. We recommend the following method of
installation:
  curl http://npmjs.org/install.sh | sh

After installing, add the following path to your NODE_PATH environment
variable to have npm libraries picked up:
  /usr/local/lib/node_modules
==> Summary
/usr/local/Cellar/node/0.8.0: 79 files, 11M, built in 3.5 minutes

npmは--without-npmで除外してあるようです。
npmは以前インストールしたので、そのままnpm installしようとしたら、以下のエラーが出てしまいました。

$ npm install
Error: npm doesn't work with node v0.8.0
Required: node@0.4 || 0.5
    at /usr/local/lib/node_modules/npm/bin/npm-cli.js:57:23
    at Object.<anonymous> (/usr/local/lib/node_modules/npm/bin/npm-cli.js:77:3)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.runMain (module.js:487:10)
    at process.startup.processNextTick.process._tickCallback (node.js:244:9)

改めてインストールしました。

$ curl http://npmjs.org/install.sh | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  7881  100  7881    0     0  11737      0 --:--:-- --:--:-- --:--:-- 25019
tar=/usr/bin/tar
version:
bsdtar 2.8.3 - libarchive 2.8.3
install npm@1.1
fetching: http://registry.npmjs.org/npm/-/npm-1.1.32.tgz
0.8.0
1.1.32
cleanup prefix=/usr/local

All clean!

> npm@1.1.32 prepublish .
> npm prune ; make -j4 doc

sh: npm: command not found
make: Nothing to be done for `doc'.
/usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
npm@1.1.32 /usr/local/lib/node_modules/npm
It worked

makeで何か出てますが、良く分からんので無視しました。ドキュメント関連でしょうか。
改めてnpm installします。

$ npm install
npm http GET https://registry.npmjs.org/express
npm http 304 https://registry.npmjs.org/express
npm http GET https://registry.npmjs.org/connect/2.3.4
npm http GET https://registry.npmjs.org/cookie/0.0.3
npm http GET https://registry.npmjs.org/mkdirp/0.3.3
npm http GET https://registry.npmjs.org/range-parser/0.0.4
npm http GET https://registry.npmjs.org/crc/0.2.0
npm http GET https://registry.npmjs.org/fresh/0.1.0
npm http GET https://registry.npmjs.org/methods/0.0.1
npm http GET https://registry.npmjs.org/commander/0.6.1
npm http GET https://registry.npmjs.org/debug
npm http 304 https://registry.npmjs.org/connect/2.3.4
npm http 304 https://registry.npmjs.org/mkdirp/0.3.3
npm http 304 https://registry.npmjs.org/crc/0.2.0
npm http 304 https://registry.npmjs.org/cookie/0.0.3
npm http 304 https://registry.npmjs.org/fresh/0.1.0
npm http 304 https://registry.npmjs.org/range-parser/0.0.4
npm http 304 https://registry.npmjs.org/methods/0.0.1
npm http 304 https://registry.npmjs.org/commander/0.6.1
npm http 304 https://registry.npmjs.org/debug
npm http GET https://registry.npmjs.org/qs/0.4.2
npm http GET https://registry.npmjs.org/mime/1.2.4
npm http GET https://registry.npmjs.org/formidable/1.0.11
npm http GET https://registry.npmjs.org/cookie/0.0.4
npm http GET https://registry.npmjs.org/fresh/0.0.1
npm http GET https://registry.npmjs.org/bytes/0.0.1
npm http 200 https://registry.npmjs.org/mime/1.2.4
npm http GET https://registry.npmjs.org/mime/-/mime-1.2.4.tgz
npm http 200 https://registry.npmjs.org/qs/0.4.2
npm http 200 https://registry.npmjs.org/fresh/0.0.1
npm http GET https://registry.npmjs.org/fresh/-/fresh-0.0.1.tgz
npm http GET https://registry.npmjs.org/qs/-/qs-0.4.2.tgz
npm http 200 https://registry.npmjs.org/bytes/0.0.1
npm http GET https://registry.npmjs.org/bytes/-/bytes-0.0.1.tgz
npm http 200 https://registry.npmjs.org/cookie/0.0.4
npm http GET https://registry.npmjs.org/cookie/-/cookie-0.0.4.tgz
npm http 200 https://registry.npmjs.org/formidable/1.0.11
npm http GET https://registry.npmjs.org/formidable/-/formidable-1.0.11.tgz
express@3.0.0beta4 node_modules/express
├── methods@0.0.1
├── fresh@0.1.0
├── range-parser@0.0.4
├── cookie@0.0.3
├── crc@0.2.0
├── commander@0.6.1
├── debug@0.7.0
├── mkdirp@0.3.3
└── connect@2.3.4 (bytes@0.0.1, fresh@0.0.1, cookie@0.0.4, qs@0.4.2, mime@1.2.4, formidable@1.0.11)

成功したようです。