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');
}).listen(8124);

console.log('Server running at http://127.0.0.1:8124/');

Installation

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 \

http://nodejs.org/dist/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.

12 Comments on "Installing Node.js on CentOS/RedHat"

  1. Boris says:

    we are now in july and current stable version is: node-v0.4.9.tar.gz, you should update the spec file, so visitors lazy as me wouldn’t have to modify it :D thanks by the way. So here is the spec file for latest version as of date (Jul 13 2011) http://borisaguilar.site50.net/nodejs.spec

  2. Greg says:

    Thanks for putting this together. I sometimes get some grief from different co-workers for taking the time to build rpm’s of one-off package requests, but it comes in handy in terms of keeping everything consistent. This is one less spec file I have to write now (phew!).

  3. el*Loco says:

    Thanx for the SPEC file, saves me lots of manual work.

  4. Michael says:

    Thanks a lot for clear explanation and spec file!

  5. Renni says:

    You might want to install these packages first: gcc gcc-c++ rpm-build

  6. Gerald says:

    Does anyone have the spec for v0.6?

  7. Sean Plaice says:

    @Gerald – I have updated the spec for 0.6.6 release you can grab it at https://gist.github.com/1572336 (not highly tested, especially npm so your mileage may vary)

  8. Frosty says:

    Thanks for putting this up. With the latest version, 0.6.10, I can build and install the RPM just fine, and node itself seems to work, but I can’t install anything with npm (on 32-bit RHEL5).

    I get this error at the unpacking stage:

    npm: ../src/node_zlib.cc:273: static void node::ZCtx::Init(node::ZCtx*, int, int, int, int) [with node::node_zlib_mode mode = UNZIP]: Assertion `err == 0′ failed.

  9. JAM says:

    Thanks to @Gerald for the initial Spec file, and to @Sean Plaice for following up :)

    I updated the spec for packaging v0.8.2 (not fully tested):
    https://gist.github.com/3143481

  10. Adri says:

    An up-to-date .spec file for node.js 0.8.14 (the latest as of now) is available here https://github.com/kazuhisya/nodejs-rpm

    And here’s a tutorial based on CentOS 6.3 and the .spec file above: http://www.adriano.ws/how-to-build-the-latest-node-js-rpm-and-install-it-on-centos-redhat-fedora

Trackbacks for this post

  1. Building RPMs for and setting up StatsD and Graphite on CentOS. | blog.milford.io
  2. Installing node.js on CentOS 6.3 | vibol.hou

Got something to say? Go for it!