Node让你可以用javascript编写服务器端程序,让javascript脱离web浏览器的限制,像C#、JAVA、Python等语言一样在服务器端运行,这也让一些熟悉Javascript的前端开发人员进军到服务器端开发提供了一个便利的途径。 Node是基于Google的V8引擎封装的,并提供了一些编写服务器程序的常用接口,例如文件流的处理。Node的目的是提供一种简单的途径来编写高性能的网络程序。
1,下载源码
在node.js的官方网站下载最新的源代码,node.js官方的升级比较快,如果没有特殊需求,还是下载最新的源码吧
地址:http://nodejs.org/download/
32bit 和 64bit根据自己需求爱好选择
我下载的是 node-v0.8.7.tar.gz,下载完解压
tar –zxvf node-v0.8.7.tar.gz
2,安装
先保证gcc之类的都已经安装好
yum install gcc gcc-c++
还需要python 一般的linux都有,版本需要2.6+ 但是好像不支持python3.×。
./configure –help
[root@local node-v0.8.7]# ./configure -help
Usage: configure [options]
Options:
-h, --help show this help message and exit
--debug Also build debug build
--prefix=PREFIX Select the install prefix (defaults to /usr/local)
--without-npm Don't install the bundled npm package manager
--without-waf Don't install node-waf
--without-ssl Build without SSL
--without-snapshot Build without snapshotting V8 libraries. You might
want to set this for cross-compiling. [Default: False]
--shared-v8 Link to a shared V8 DLL instead of static linking
--shared-v8-includes=SHARED_V8_INCLUDES
Directory containing V8 header files
--shared-v8-libpath=SHARED_V8_LIBPATH
A directory to search for the shared V8 DLL
--shared-v8-libname=SHARED_V8_LIBNAME
Alternative lib name to link to (default: 'v8')
--shared-openssl Link to a shared OpenSSl DLL instead of static linking
--shared-openssl-includes=SHARED_OPENSSL_INCLUDES
Directory containing OpenSSL header files
--shared-openssl-libpath=SHARED_OPENSSL_LIBPATH
A directory to search for the shared OpenSSL DLLs
--shared-openssl-libname=SHARED_OPENSSL_LIBNAME
Alternative lib name to link to (default:
'crypto,ssl')
--no-ssl2 Disable OpenSSL v2
--shared-zlib Link to a shared zlib DLL instead of static linking
--shared-zlib-includes=SHARED_ZLIB_INCLUDES
Directory containing zlib header files
--shared-zlib-libpath=SHARED_ZLIB_LIBPATH
A directory to search for the shared zlib DLL
--shared-zlib-libname=SHARED_ZLIB_LIBNAME
Alternative lib name to link to (default: 'z')
--with-dtrace Build with DTrace (default is true on supported
systems)
--without-dtrace Build without DTrace
--with-etw Build with ETW (default is true on Windows)
--without-etw Build without ETW
--gdb add gdb support
--dest-cpu=DEST_CPU CPU architecture to build for. Valid values are: arm,
ia32, x64
--no-ifaddrs Use on deprecated SunOS systems that do not support
ifaddrs.h
--with-arm-float-abi=ARM_FLOAT_ABI
Specifies which floating-point ABI to use. Valid
values are: soft, softfp, hard
默认安装在/usr/local下
没有什么特殊需求的,就直接
[root@local node-v0.8.7]# ./configure
{ 'target_defaults': { 'cflags': [],
'default_configuration': 'Release',
'defines': [],
'include_dirs': [],
'libraries': []},
'variables': { 'clang': 0,
'gcc_version': 44,
'host_arch': 'x64',
'node_install_npm': 'true',
'node_install_waf': 'true',
'node_prefix': '',
'node_shared_openssl': 'false',
'node_shared_v8': 'false',
'node_shared_zlib': 'false',
'node_use_dtrace': 'false',
'node_use_etw': 'false',
'node_use_openssl': 'true',
'target_arch': 'x64',
'v8_no_strict_aliasing': 1,
'v8_use_snapshot': 'true'}}
creating ./config.gypi
creating ./config.mk
[root@local node-v0.8.7]# make
[root@local node-v0.8.7]# make install
如果不报错就安装ok了
测试一下 建一个server.js,代码如下:
var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(80, '127.0.0.1'); console.log('Server running at http://127.0.0.1:/');
[root@local ~]# node server.js
浏览器打开http://127.0.0.1
如果没有图形界面,127.0.0.1地址修改为对应服务器ip,然后访问http://×××/