Installing Node.js on CentOS/RedHat

Node.js, if you are not yet familiar with it, facilitates building event-driven server-side javascript services. Services built with Node.js go to sleep after instructing the operating system to wake them if a connection is made (via epoll, kqueue, /dev/poll or select). Additionally, each connection is only a small heap allocation, as opposed to spawning a 2M thread/child for each connection like some other popular web services.

Node.js is a server-side JavaScript environment that uses an asynchronous event-driven model. This allows Node.js to get excellent performance based on the architectures of many Internet applications.

The event-driven model and Node.js framework makes it ridiculously simple to build web services like the following “Hello World” example from the Node.js webpage:

var http = require('http');

http.createServer(function (request, response) {
  response.writeHead(200, {'Content-Type': 'text/plain'});
  response.end('Hello World\n');

console.log('Server running at');


The online wiki provides instructions on installing Node.js as an unmanaged package, but I prefer to handle as much as possible with RPM. To that end, I put together a simple spec file that can be used to build Node.js RPMs for use on RedHat or CentOS systems (or any other system that uses RPM as a package management tool).

The first thing you’ll need to do is download the latest Node.js source package. At the time of this writing, v0.4.6 is the most current version of Node.js available. I like to use curl to download the sources directly into the default rpm sources directory, but you could also use wget or simply download the package via your web browser. You’ll also need to make sure that Node.js source ends up in the right place if you are not building the RPM as root, or if you like to put your build structure somewhere other than /usr/src/redhat.

curl -sR -o /usr/src/redhat/SOURCES/node-v0.4.6.tar.gz \

Once you have the source in place, download the Node.js spec file and place it into /usr/src/redhat/SPECS (or the appropriate spec folder). To build the RPM, execute rpmbuild as follows:

rpmbuild -ba /usr/src/redhat/SPECS/nodejs.spec

Once the build completes, you will find your RPMs in the /usr/src/redhat/RPMS folder.

More Information

For more information about Node.js, visit the following online resources:

Chris Abernethy
PHP Wrangler, MySQL DBA, Linux SysAdmin and all around computer guy, developing LAMP applications since Slackware came on 10 floppy disks.

Got something to say? Go for it!