normalian blog

Let's talk about Microsoft Azure, ASP.NET and Java!

Node.js のパッケージ管理システム npm を Windows で利用する

以下のブログを参照し、Windows 版の npm 環境を構築する。

事前にインストールする必要のあるソフトウェア

npm をインストールする前に、Git と Python をインストールする必要がある。

Git については以下の記事を参照して頂きたい。

セットアップ時に「Run Git from the Windows Command Prompt」を設定する点に留意してほしい。その他はデフォルトの設定で問題ない。

Python については、以下のサイトからバイナリをダウンロードして頂きたい。2.7.X系の32bit版バイナリをダウンロードし、デフォルトのまま設定すればインストール完了だ。

両ソフトウェアのインストール後、以下の様にバージョンを確認し、実行ファイルに対するパスが遠いっているかを確認すること。

npm のインストール

Git と Python のインストールが完了した後、以下のコマンドを実行することで Windows版の npm をインストールすることが可能だ(コマンドについての詳細な説明は割愛する)。

C:\node\v0.6.1>set NODE_PATH=c:\node\lib

C:\node\v0.6.1>set NODE_HOME=c:\node\v0.6.1

C:\node\v0.6.1>node -v
v0.6.1

C:\node\v0.6.1>git config --system http.sslcainfo /bin/curl-ca-bundle.crt

C:\node\v0.6.1>git clone --recursive git://github.com/isaacs/npm.git
Cloning into npm...
remote: Counting objects: 16854, done.
remote: Compressing objects: 100% (4458/4458), done.
remote: Total 16854 (delta 12592), reused 16505 (delta 12293)
Receiving objects: 100% (16854/16854), 4.96 MiB | 1.08 MiB/s, done.
Resolving deltas: 100% (12592/12592), done.
(中略)

C:\node\v0.6.1>cd npm

C:\node\v0.6.1\npm>node cli.js install npm -gf
C:\node\v0.6.1\npm-g -> C:\node\v0.6.1\node_modules\npm\bin\npm-cli.js
C:\node\v0.6.1\npm -> C:\node\v0.6.1\node_modules\npm\bin\npm-cli.js
C:\node\v0.6.1\npm_g -> C:\node\v0.6.1\node_modules\npm\bin\npm-cli.js
npm@1.0.105 C:\node\v0.6.1\node_modules\npm

C:\node\v0.6.1\npm>npm -h

Usage: npm <command>

where <command> is one of:
    adduser, apihelp, author, bin, bugs, c, cache, completion,
    config, deprecate, docs, edit, explore, faq, find, get,
    help, help-search, home, i, info, init, install, la, link,
    list, ll, ln, ls, outdated, owner, pack, prefix, prune,
    publish, r, rb, rebuild, remove, restart, rm, root,
(中略)

socket.io をインストールする

npm のセットアップ完了後、以下の様にパッケージのインストールが可能となる。依存関係も含めてパッケージがインストールされていることが確認できる。

C:\node\v0.6.1>npm install socket.io
socket.io@0.8.7 ./node_modules/socket.io
├── redis@0.6.7
├── policyfile@0.0.4
└── socket.io-client@0.8.7