How to Install Node.js

This was the first in a series of posts leading up to Node.js Knockout on how to use node.js.

I have been given permission to repost the articles from the contest here (in wheat format) for general consumption. Expect more to come.

In this post we detail how to install node on MacUbuntu, and Windows.

Mac

If you're using the excellent homebrew package manager, you can install node with one command: brew install node.

Otherwise, follow the below steps:

  1. Install Xcode.
  2. Install git.
  3. Run the following commands:
darwin_setup.sh
git clone git://github.com/ry/node.git
cd node
./configure
make
sudo make install

You can check it worked with a simple Hello, World! example.

Ubuntu

  1. Install the dependencies:

    • sudo apt-get install g++ curl libssl-dev apache2-utils
    • sudo apt-get install git-core
  2. Run the following commands:

ubuntu_setup.sh
git clone git://github.com/ry/node.git
cd node
./configure
make
sudo make install

You can check it worked with a simple Hello, World! example.

Thanks to code-diesel for the Ubuntu dependencies.

Windows

Currently, you must use cygwin to install node. To do so, follow these steps:

  1. Install cygwin.
  2. Use setup.exe in the cygwin folder to install the following packages:

    • devel → openssl
    • devel → g++-gcc
    • devel → make
    • python → python
    • devel → git
  3. Open the cygwin command line with Start > Cygwin > Cygwin Bash Shell.

  4. Run the below commands to download and build node.
cygwin_setup.sh
git clone git://github.com/ry/node.git
cd node
./configure
make
sudo make install

For more details, including information on troubleshooting, please see the GitHub wiki page.

Hello Node.js!

Here's a quick program to make sure everything is up and running correctly:

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

Run the code with the node command line utility:

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

Now, if you navigate to http://127.0.0.1:8124/ in your browser, you should see a nice message.

Congrats!

You've installed node.js.


转帖:http://howtonode.org/how-to-install-nodejs

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值