如何安装Node.js

本文分别介绍在Mac, Ubuntu,Centos以及Windows下安装Node.js.
首页 新闻资讯 行业资讯 如何安装Node.js

下面分别介绍在Mac, Ubuntu,Centos以及Windows下安装Node.js.

Mac

在Mac下,如果你喜欢用homebrew,那么只用一行就可以装好:

复制

brew install node
  • 1.

否则,只能考虑手工安装了,步骤如下:

1. 安装Xcode

2. 安装git

3 .运行下面的命令行编译node.js

复制

git clone git://github.com/joyent/node.git  cd node  ./configure  make  sudo make install
  • 1.

  • 2.

  • 3.

  • 4.

  • 5.

Ubuntu

安装依赖包

复制

sudo apt-get install g++ curl libssl-dev apache2-utils  sudo apt-get install git-core
  • 1.

  • 2.

运行下面的命令行:

复制

git clone git://github.com/joyent/node.git  cd node  ./configure  make  sudo make install
  • 1.

  • 2.

  • 3.

  • 4.

  • 5.

Windows

用cygwin来安装node,步骤如下:

1. 安装cygwin

2  在cygwin的目录下,运行setup.exe安装下面列表中的包

◆ devel → openssl

◆ devel → g++-gcc

◆ devel → make

◆ python → python

◆ devel → git

3.  运行cygwin

4.  运行下面的命令行:

复制

git clone git://github.com/joyent/node.git  cd node  ./configure  make  sudo make install
  • 1.

  • 2.

  • 3.

  • 4.

  • 5.

Centos

复制

yum install gcc-c++ openssl-devel  wget --no-check-certificate https://github.com/joyent/node/tarball/v0.3.3  tar -xzvf ry-node-v0.3.3-0-g57544ba.tar.gz  cd ry-node-v0.3.3-0-g57544bac1  ./configure  make  make install
  • 1.

  • 2.

  • 3.

  • 4.

  • 5.

  • 6.

  • 7.

Hello Node.js!

写一段小程序例如hello_node.js来验证安装是否正确:

复制

var http = require('http');  http.createServer(function (req, res) {    res.writeHead(200, {'Content-Type': 'text/plain'});    res.end('Hello Node.jsn');  }).listen(8124, "127.0.0.1");  console.log('Server running at http://127.0.0.1:8124/');
  • 1.

  • 2.

  • 3.

  • 4.

  • 5.

  • 6.

用node来运行这段代码

复制

node hello_node.js  Server running at http://127.0.0.1:8124/
  • 1.

  • 2.

现在,用浏览器打开 http://127.0.0.1:8124/ , 应该能够看到一条好消息。

参考文档

How to Install Node.js  http://howtonode.org/how-to-install-nodejs

Update

补充了在centos上安装Node.js的步骤

原文:http://www.ooso.net/archives/589

【编辑推荐】

  1. Node.js中实现文件的循环写入

  2. Node.js源码研究之模块组织加载

  3. 揭秘Node.js事件

  4. Node.js初探之与Mysql的交互

  5. Node.js入门之神秘的服务器端JavaScript

11    2011-09-09 14:23:13    Node.js