摘要:本篇Node.js教程探讨了如何安装Node.js,希望阅读本篇文章以后大家有所收获,帮助大家对Node.js的理解更加深入。
下面分别介绍在Mac, Ubuntu,Centos以及Windows下安装Node.js.
Mac
在Mac下,如果你喜欢用homebrew,那么只用一行就可以装好:
1. brew install node
否则,只能考虑手工安装了,步骤如下:
1. 安装Xcode
2. 安装git
3 .运行下面的命令行编译node.js
1. git clone git://github.com/joyent/node.git
2. cd node
3. ./configure
4. make
5. sudo make install
Ubuntu
安装依赖包
1. sudo apt-get install g++ curl libssl-dev apache2-utils
2. sudo apt-get install git-core
运行下面的命令行:
1. git clone git://github.com/joyent/node.git
2. cd node
3. ./configure
4. make
5. sudo make install
Windows
用cygwin来安装node,步骤如下:
1. 安装cygwin
2 在cygwin的目录下,运行setup.exe安装下面列表中的包
◆ devel → openssl
◆ devel → g++-gcc
◆ devel → make
◆ python → python
◆ devel → git
3. 运行cygwin
4. 运行下面的命令行:
1. git clone git://github.com/joyent/node.git
2. cd node
3. ./configure
4. make
5. sudo make install
Centos
1. yum install gcc-c++ openssl-devel
2. wget --no-check-certificate https://github.com/joyent/node/tarball/v0.3.3
3. tar -xzvf ry-node-v0.3.3-0-g57544ba.tar.gz
4. cd ry-node-v0.3.3-0-g57544bac1
5. ./configure
6. make
7. make install
Hello Node.js!
写一段小程序例如hello_node.js来验证安装是否正确:
1. var http = require('http');
2. http.createServer(function (req, res) {
3. res.writeHead(200, {'Content-Type': 'text/plain'});
4. res.end('Hello Node.jsn');
5. }).listen(8124, "127.0.0.1");
6. console.log('Server running at //127.0.0.1:8124/');
用node来运行这段代码
1. node hello_node.js
2. Server running at //127.0.0.1:8124/
现在,用浏览器打开 //127.0.0.1:8124/ , 应该能够看到一条好消息。
本文由职坐标整理发布,更多相关知识,请关注职坐标WEB前端Node.js频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号