Adriano Chiaretta

How to build the latest node.js RPM and install it on CentOS / RedHat / Fedora

If you aren’t familiar with node.js, it’s a platform whose goal is to facilitate building event-driven server side javascript services. Essentially it allows to run javascript on the server — services built with Node.js go to sleep after instructing the operating system to wake them if a connection is made, and each connection has a very small memory footprint.

I recently started getting into nodejs, and first thing to figure out has been the best way to install it on a CentOS virtual server I had around, and here’s a summary of my findings.

In order to install nodejs on RedHat / CentOS / Fedora the most common approach is to grab the latest sources tarball and build them, and the instructions for this are on the online wiki. This will install node.js as an unmanaged package, making upgrade or uninstallation at times not super straightforward.

Which is why, on RedHat based distros (such as CentOS) I prefer going for handling software installations through RPM. In the past there were some ready-made node.js RPMs, but no new ones have been produced after version 0.6.18 (and we are now at 0.8.x).

So I went for building the RPMs myself, and listed below are the steps I went through.

– If your CentOS box doesn’t have compiler related components, install them with yum as usual:

yum groupinstall “Development tools”

– Install also the  gcc-c++ build tools (needed by the RPM build environment)

yum install gcc-c++

– Setup the RPM build environment, following what outlined on the CentOS wiki — afterward your home user’s folder show include the following subfolders:

– Download the latest node.js sources in the SOURCES folder

curl -sR -o ~/rpmbuild/SOURCES/node-v0.8.14.tar.gz http://nodejs.org/dist/v0.8.14/node-v0.8.14.tar.gz

– In order to build an RPM you’ll need its definition (.spec) file, and someone out there is kind enough to maintain one up to date with the latest node.js versions. Download it in the SPECS folder:

curl -sR -o ~/rpmbuild/SPECS/node-v0.8.14.spec https://github.com/kazuhisya/nodejs-rpm/raw/master/nodejs.spec

– At this point you’re ready to fire up rpmbuild:

rpmbuild -ba ~/rpmbuild/SPECS/node-v0.8.14.spec

– Depending on how fast your machine is, after a few minutes unless surprises the build and packaging process will complete and under ~/rpmbuild/RPMS/<architecture> you’ll find the node.js binaries and source RPMs.

– In my case, being the CentOS box a 64 bit one, I found what was looking for at: ~/rpmbuild/RPMS/x86_64/nodejs-0.8.14-1.el6.x86_64.rpm

– At last, time to install node.js:

rpm -ivh ~/rpmbuild/RPMS/x86_64/nodejs-0.8.14-1.el6.x86_64.rpm

– once installed, you can verify if things went correctly by checking that the “node” executable can be found within the path (doing a “which node”) and node –version which should output the version of the node binary just installed.

If you wish to cut a few corners and avoid the steps above, you can find the node.js 0.8.14 RPMs at this location (note that they have been built on an x64 CentOS 6.3 box — haven’t tried them on other versions or distros).

Leave a Comment