Linuxの勉強がてらインストールしてみました。
まだド素人のため、それぞれのコマンドの意味はまだはっきりと理解でできていません
勉強していきます(^_^;)
実行環境はさくらVPSの1Gのプランです
http://vps.sakura.ad.jp/specification.html
naveのインストール
nodeの代表的なバージョン管理システムのnaveをインストールします。
まずはgithubからnaveをダウンロードします
$ git clone git://github.com/isaacs/nave.git
naveをダウンロードしたディレクトリに行き、nodeをインストールします。
$ ./nave.sh install latest
なんかエラーになります。
make[1]: Leaving directory `/home/kamatama41/.nave/src/0.7.7/out' make: *** [node] Error 2 Failed to make 0.7.7 fail
nvmのインストールとnodeのインストール
うまくいかないみたいなので、代表的なもうひとつの管理システムのnvmをインストールします。
最初は同じくgithubからnaveをダウンロードします
$ git clone git://github.com/creationix/nvm.git ~/.node
nvmをダウンロードしたディレクトリに行き、nodeをインストールします。
2012/4/9時点での最新安定版は0.6.14です。
$ . ~/.node/nvm.sh $ nvm install v0.6.14
なんかエラーになります。
######################################################################## 100.0% Checking for program g++ or c++ : /usr/bin/g++ Checking for program cpp : /usr/bin/cpp Checking for program ar : /usr/bin/ar Checking for program ranlib : /usr/bin/ranlib Checking for g++ : ok Checking for program gcc or cc : /usr/bin/gcc Checking for gcc : ok Checking for library dl : yes Checking for openssl : not found Checking for function SSL_library_init : not found Checking for header openssl/crypto.h : not found /home/kamatama41/.node/src/node-v0.6.14/wscript:374: error: Could not autodetect OpenSSL support. Make sure OpenSSL development packages are installed. Use configure --without-ssl to disable this message. nvm: install v0.6.14 failed! fail
OpenSSLの開発ツールを入れないとダメなようです。
$ sudo yum install openssl-devel
開発ツールの有無は以下のコマンドで確認します。
$ rpm -qa | grep openssl
npmを使う
node.js系のライブラリ管理システムnpmを使います。
とりあえずsocket.ioをインストールしてみます。
$ npm install socket.io
~/.node配下にnode_modulesディレクトリが作成されています。
次に、expressをインストールしてみます。-gをつけることで、
{NODE_HOME}/lib/node_modules/express/bin/express配下にパッケージをインストールして
パスを通してくれるみたいです。
$ npm install express -g
JSを書いてみる
以下のファイルをapp.jsとして、~/.node配下に作成します。
var express = require("express"), app = express.createServer(), port = process.env.PORT || 3000; app.configure(function() { app.use(app.router); }) app.get("/",function(req, res) { res.end("hello world!!"); }) app.listen(port);
今の時点で謎な点
~/.node配下にjsを置かないと、expressがありませんと怒られる。
nodeにおけるモジュール、パスの概念を把握しないといけません。
Error: Cannot find module 'express' at Function._resolveFilename (module.js:332:11) at Function._load (module.js:279:25) at Module.require (module.js:354:17) at require (module.js:370:17) at Object.<anonymous> (/home/kamatama41/app.js:1:67) at Module._compile (module.js:441:26) at Object..js (module.js:459:10) at Module.load (module.js:348:31) at Function._load (module.js:308:12) at Array.0 (module.js:479:10)