CentOS 6下安装nodejs 0.9.0
2016-12-16 00:00
435 查看
确保安装了python,大部分安装失败都是由于python版本过低导致。安装之前,升级python版本,升级步骤 http://www.tomtalk.net/wiki/Python。
[root@SNDA-192-168-15-161 ~]# python -V
Python 2.7.3
开始安装:
1).下载nodejs到本地并解压缩
[root@SNDA-192-168-15-161 node]# wget http://nodejs.org/dist/v0.9.0/node-v0.9.0.tar.gz [root@SNDA-192-168-15-161 node]# tar zxvf node-v0.9.0.tar.gz
2).进入到该目录编译和安装
[root@SNDA-192-168-15-161 node-v0.9.0]# cd node-v0.9.0
[root@SNDA-192-168-15-161 node-v0.9.0]# ./configure --prefix=/usr/local/node/0.9.0
这里安装在了/usr/local/node/0.9.0目录下
[root@SNDA-192-168-15-161 node-v0.9.0]# make
[root@SNDA-192-168-15-161 node-v0.9.0]# make install
3).配置NODE_HOME
[root@SNDA-192-168-15-161 node-v0.9.0]# vi /etc/profile
在export PATH USER 。。。一行的上面添加如下内容,并将NODE_HOME/bin设置到系统path中
#set for nodejs
export NODE_HOME=/usr/local/node/0.9.0
export PATH=$NODE_HOME/bin:$PATH
保存退出后执行如下命令,使刚才的配置生效
[root@SNDA-192-168-15-161 node-v0.9.0]# source /etc/profile
执行node -h命令验证设置成功
[root@SNDA-192-168-15-161 ~]# node -h
Usage: node [options] [ -e script | script.js ] [arguments]
node debug script.js [arguments]
Options:
-v, --version print node's version
-e, --eval script evaluate script
-p, --print print result of --eval
-i, --interactive always enter the REPL even if stdin
does not appear to be a terminal
--no-deprecation silence deprecation warnings
--trace-deprecation show stack traces on deprecations
--v8-options print v8 command line options
--max-stack-size=val set max v8 stack size (bytes)
Environment variables:
NODE_PATH ':'-separated list of directories
prefixed to the module search path.
NODE_MODULE_CONTEXTS Set to 1 to load modules in their own
global contexts.
NODE_DISABLE_COLORS Set to 1 to disable colors in the REPL
Documentation can be found at http://nodejs.org/
至此安装设置完毕。
运行一个简单的node应用程序 + socket.io,首先需要安装socket.io模块
[root@SNDA-192-168-15-161 ~]# npm install socket.io
[root@SNDA-192-168-15-161 ~]# vi app.js
var http=require('http');
var io =require('socket.io');
var server = http.createServer(function(req,res){
res.writeHead(200,{'Content-Type':'text/plain'});
res.end('Hello world');
});
server.listen(process.argv[2]);
var socket = io.listen(server);
socket.on('connection',function(client){
console.log('client has connected');
client.on('message',function(){ });
});
[root@SNDA-192-168-15-161 ~]# nodejs ./app.js 8001 &
[root@SNDA-192-168-15-161 ~]# nodejs ./app.js 8002 &
[root@SNDA-192-168-15-161 ~]# nodejs ./app.js 8003 &
[root@SNDA-192-168-15-161 ~]# nodejs ./app.js 8004 &
更详细的参照socket.io的官网的例子。
[root@SNDA-192-168-15-161 ~]# python -V
Python 2.7.3
开始安装:
1).下载nodejs到本地并解压缩
[root@SNDA-192-168-15-161 node]# wget http://nodejs.org/dist/v0.9.0/node-v0.9.0.tar.gz [root@SNDA-192-168-15-161 node]# tar zxvf node-v0.9.0.tar.gz
2).进入到该目录编译和安装
[root@SNDA-192-168-15-161 node-v0.9.0]# cd node-v0.9.0
[root@SNDA-192-168-15-161 node-v0.9.0]# ./configure --prefix=/usr/local/node/0.9.0
这里安装在了/usr/local/node/0.9.0目录下
[root@SNDA-192-168-15-161 node-v0.9.0]# make
[root@SNDA-192-168-15-161 node-v0.9.0]# make install
3).配置NODE_HOME
[root@SNDA-192-168-15-161 node-v0.9.0]# vi /etc/profile
在export PATH USER 。。。一行的上面添加如下内容,并将NODE_HOME/bin设置到系统path中
#set for nodejs
export NODE_HOME=/usr/local/node/0.9.0
export PATH=$NODE_HOME/bin:$PATH
保存退出后执行如下命令,使刚才的配置生效
[root@SNDA-192-168-15-161 node-v0.9.0]# source /etc/profile
执行node -h命令验证设置成功
[root@SNDA-192-168-15-161 ~]# node -h
Usage: node [options] [ -e script | script.js ] [arguments]
node debug script.js [arguments]
Options:
-v, --version print node's version
-e, --eval script evaluate script
-p, --print print result of --eval
-i, --interactive always enter the REPL even if stdin
does not appear to be a terminal
--no-deprecation silence deprecation warnings
--trace-deprecation show stack traces on deprecations
--v8-options print v8 command line options
--max-stack-size=val set max v8 stack size (bytes)
Environment variables:
NODE_PATH ':'-separated list of directories
prefixed to the module search path.
NODE_MODULE_CONTEXTS Set to 1 to load modules in their own
global contexts.
NODE_DISABLE_COLORS Set to 1 to disable colors in the REPL
Documentation can be found at http://nodejs.org/
至此安装设置完毕。
运行一个简单的node应用程序 + socket.io,首先需要安装socket.io模块
[root@SNDA-192-168-15-161 ~]# npm install socket.io
[root@SNDA-192-168-15-161 ~]# vi app.js
var http=require('http');
var io =require('socket.io');
var server = http.createServer(function(req,res){
res.writeHead(200,{'Content-Type':'text/plain'});
res.end('Hello world');
});
server.listen(process.argv[2]);
var socket = io.listen(server);
socket.on('connection',function(client){
console.log('client has connected');
client.on('message',function(){ });
});
[root@SNDA-192-168-15-161 ~]# nodejs ./app.js 8001 &
[root@SNDA-192-168-15-161 ~]# nodejs ./app.js 8002 &
[root@SNDA-192-168-15-161 ~]# nodejs ./app.js 8003 &
[root@SNDA-192-168-15-161 ~]# nodejs ./app.js 8004 &
更详细的参照socket.io的官网的例子。
相关文章推荐
- centos6.2下搭建Web服务器
- linux命令学习--cp
- Linux命令学习手册-arp命令
- Linux 驱动常见错误返回值
- Linux 查看usb设备信息
- CentOS下进入MySQL提示ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
- linux查看系统类型和版本
- ---Linux 10 年的硕果累累啊!
- Linux模块编程框架
- sudo详解
- arm-linux-gnueabi-gcc是什么?
- signal linux kernel 实现 浅析
- 最近在整linux
- Ubunut 12.0.4 Git安装和使用
- Linux中使用ipvsadm配置LVS集群的基本方法
- Linux-软件安装管理rpm/yum/源码包编译安装
- D01_01Linux简单操作与JDK安装
- linux下如何反汇编
- linux下如何反汇编
- linux下如何反汇编