linux编译安装配置node.js

linux编译安装配置node.js

安装环境

  centos7.3             192.168.1.22

安装步骤
1.下载源码

wget http://nodejs.org/dist/v0.10.24/node-v0.10.24.tar.gz
  1. 解压源码
tar zxvf node-v0.10.24.tar.gz
  1. 编译安装 指定路径
cd node-v0.10.24
./configure --prefix=/usr/local/node/0.10.24
make && make install
  1. 配置环境变量
vi /etc/profile  #末尾添加
export NODE_HOME=/usr/local/node/0.10.24
export PATH=$NODE_HOME/bin:$PATH
source /etc/profile  #使变量生效

验证安装是否成功

node -v

注:npm模块安装路径 /usr/local/node/0.10.24/lib/node_modules/

test 测试 创建应用– hello word

vi wanbo.js
var http = require('http');

http.createServer(function (request, response) {

    // 发送 HTTP 头部 
    // HTTP 状态值: 200 : OK
    // 内容类型: text/plain
    response.writeHead(200, {'Content-Type': 'text/plain'});

    // 发送响应数据 "Hello World"
    response.end('Hello World\n');
}).listen(8888);

// 终端打印如下信息
console.log('Server running at http://127.0.0.1:8888/');

保存!
使用node命令执行代码:

node wanbo.js
Server running at http://127.0.0.1:8888/

这里写图片描述

windows 访问服务器地址+端口 192.168.1.22:8888
这里写图片描述

猜你喜欢

转载自blog.csdn.net/qq_40025218/article/details/81561032