This is the 1st in series of posts leading up to the 4th annual Node.js Knockout about how to use node.js.

This post covers how to install node and npm on three popular development platforms: Mac, Ubuntu, and Windows.

Instructions for other platforms can be found on the Node Wiki.

The Easy Way

We personally use package managers to make it easier to keep our node installation up to date, so that’s the approach we generally describe below.

However if you want to skip the steps and download pre-built binaries, you can do so at Joyent’s site: download a binary.

Mac

  1. Go to nodejs.org.
  2. Click install, (to download the pkg).
  3. Open the pkg and run through the install process.

That’s it! Check it worked with a simple Hello, World! example.

Ubuntu

On the latest version of Ubuntu, you can simply:

sudo apt-get install nodejs nodejs-dev npm

On earlier versions, you might need to update your repository:

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs nodejs-dev npm

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

Windows

Since Windows package managers are less common, we recommend just downloading the Windows binary.

Other Linux distributions

If you need help installing in other Linux distributions, you can consult Joyent guide for Mint, Elementary OS, Debian, LMDE, openSUSE, SLE, Fedora, RHEL/CentOS/Scientific Linux 6, Arch Linux and more.

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 command by typing node hello_node.js in your terminal.

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

Congrats

You’ve installed node.js and npm.

  1. kidshenlong reblogged this from nodeknockout
  2. nodeknockout posted this
Blog comments powered by Disqus