博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CentOS 6下安装nodejs 0.9.0
阅读量:2242 次
发布时间:2019-05-09

本文共 2219 字,大约阅读时间需要 7 分钟。

确保安装了python,大部分安装失败都是由于python版本过低导致。安装之前,升级python版本,升级步骤 http://www.tomtalk.net/wiki/Python。
一)安装nodejs
# python -V
Python 2.7.3
开始安装:
1).下载nodejs到本地并解压缩
# wget http://nodejs.org/dist/v0.9.0/node-v0.9.0.tar.gz
# tar zxvf node-v0.9.0.tar.gz
2).进入到该目录编译和安装
# cd node-v0.9.0
# ./configure --prefix=/usr/local/node/0.9.0
这里安装在了/usr/local/node/0.9.0目录下
# make
# make install
3).配置NODE_HOME
# 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
保存退出后执行如下命令,使刚才的配置生效
# source /etc/profile
执行node -h命令验证设置成功
# 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/
至此安装设置完毕。
二).安装npm
npm config set strict-ssl false
不然安装socket.io模块会报错
npm ERR! Error: SSL Error: SELF_SIGNED_CERT_IN_CHAIN
二).安装socket.io模块
运行一个简单的node应用程序 + socket.io,首先需要安装socket.io模块
# npm install socket.io
# 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(){ });
});
# nodejs ./app.js 8001 &
# nodejs ./app.js 8002 &
# nodejs ./app.js 8003 &
# nodejs ./app.js 8004 &
来自于:
http://www.cnblogs.com/shanyou/archive/2012/08/18/2645960.html
http://www.xiaocai.name/post/cf1f9_7b6507
http://socket.io/download/
你可能感兴趣的文章
【LEETCODE】36-Valid Sudoku
查看>>
【LEETCODE】205-Isomorphic Strings
查看>>
【LEETCODE】204-Count Primes
查看>>
【LEETCODE】228-Summary Ranges
查看>>
【LEETCODE】27-Remove Element
查看>>
【LEETCODE】66-Plus One
查看>>
【LEETCODE】26-Remove Duplicates from Sorted Array
查看>>
【LEETCODE】118-Pascal's Triangle
查看>>
【LEETCODE】119-Pascal's Triangle II
查看>>
word2vec 模型思想和代码实现
查看>>
怎样做情感分析
查看>>
用深度神经网络处理NER命名实体识别问题
查看>>
用 RNN 训练语言模型生成文本
查看>>
RNN与机器翻译
查看>>
用 Recursive Neural Networks 得到分析树
查看>>
RNN的高级应用
查看>>
TensorFlow-7-TensorBoard Embedding可视化
查看>>
轻松看懂机器学习十大常用算法
查看>>
一个框架解决几乎所有机器学习问题
查看>>
特征工程怎么做
查看>>