Linux环境下安装Node.js

Linux环境下安装Node.js

1. 下载nodejs安装包
如图下载 node-v5.12.0-linux-x64.tar.gz 。
Linux环境下安装Node.js

2. 解压压缩包
# tar -xzvf node-v5.12.0-linux-x64.tar.gz

3. 测试命令
# cd node-v5.12.0-linux-x64
# ./bin/node -v
v5.12.0

4. 测试
创建nodejs项目目录:
# mkdir -p /data/nodejs/

创建一个名为helloWorld.js的文件:
# cd /data/nodejs/
# vi helloWorld.js

文件内容如下: 
var http = require("http");
http.createServer(function(request, response){
        response.writeHead(200, {
                "Content-Type" : "text/plain"
        });
        response.write("Hello World");
        response.end();
}).listen(8100);
console.log("nodejs start listen 8100 port!");

运行程序:
# cd node-v5.12.0-linux-x64
# ./bin/node /data/nodejs/helloWorld.js

浏览器访问:

http://192.168.2.2:8100/

Linux环境下安装Node.js


安装完毕。