下载源码
sudo apt-get install git-core cd ~/test/node git clone https://github.com/joyent/node.git git太慢,可以直接下一个http://nodejs.org/dist/node-v0.4.8.tar.gz
下载库
sudo apt-get install g++ sudo apt-get install libssl-dev 不然编译时会报错 //无g++环境 Checking for program g++ or c++ : not found Checking for program icpc : not found Checking for program c++ : not found //libssl-dev未安装 Checking for openssl : not found Checking for function SSL_library_init : not found Checking for header openssl/crypto.h : not found
开始编译
进入下载解压的node文件夹的根目录
export JOBS=2 # optional, sets number of parallel commands.
mkdir ~/local
./configure --prefix=$HOME/local/node
make
make install
echo 'export PATH=$HOME/local/node/bin:$PATH' >> ~/.profile
source ~/.profile
NPM包管理器
curl http://npmjs.org/install.sh | sh
HelloWorld
写到hw.js:
var
sys = require('sys')
,http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('Hello World');
res.close();
}).listen(8080);
sys.puts('Server running at http://127.0.0.1:8080/');
运行:
node hw.js
到浏览器输入http://127.0.0.1:8080/ 出现 Hello World.