天天看點

安裝Node.js

安裝Node.js

下面分别介紹在Mac、Ubuntu、Centos及Windows下安裝Node.js。Node.JS最新版本為:0.6.10

在Mac下,如果你喜歡用homebrew,那麼隻用一行就可以裝好:

1 brew install node 

否則,隻能考慮手工安裝了,步驟如下:

1. 安裝Xcode

2. 安裝git

3 .運作下面的指令行編譯node.js

2 git clone git://github.com/joyent/node.git  

3 cd node  

4 ./configure  

5 make  

6 sudo make install 

安裝依賴包

1 sudo apt-get install g++ curl libssl-dev apache2-utils  

2 sudo apt-get install git-core 

運作下面的指令行:

3 git clone git://github.com/joyent/node.git  

4 cd node  

5 ./configure  

6 make  

7 sudo make install 

要安裝最新的node-v0.6.10.msi,下載下傳http://nodejs.org/dist/v0.6.10/node-v0.6.10.msi,然後直接運作,它會自動完成Node.JS的安裝。然後在指令行可以直接運作Node.JS的程式。

注:我執行了以下幾步完成安裝。

1)yum install gcc-c++ openssl-devel

2)下載下傳http://nodejs.org/dist/v0.6.10/node-v0.6.10.tar.gz

3)tar zvxf node-v0.6.10.tar.gz

4)./configure

5)make

6)make install

安裝成功!

寫一段小程式例如hello_node.js來驗證安裝是否正确:

var http=require('http');  

http.createServer(function(req,res){  

  res.writeHead(200, {'Content-Type':'text/plain'});  

  res.end('Hello Node.js');  

}).listen(8124, "127.0.0.1");  

console.log('Server running at http://127.0.0.1:8124/');  

用node來運作這段代碼

node hello_node.js  

Server running at http://127.0.0.1:8124/  

現在,用浏覽器打開 http://127.0.0.1:8124/ , 應該能夠看到一條消息。

安裝Node.js