Skip to content

Installing node.js 0.10 on CentOS5

CentOS5+Node I have an old stable internal server that’s running CentOS 5.10 which I want to use a staging/development server for modern node.js applications.

The problem is, current prebuilt versions of node.js can’t be installed on CentOS5, since CentOS5 has GNU libc 2.5 and the prebuilt node.js RPMs are only for Fedora/RedHat/CentOS 6, and are linked against libc 2.7.

Fortunately you can still build from source, as follows:

Install Python 2.7 on CentOS5

Node requires Python 2.6 or 2.7 to build; CentOS 5 comes with Python 2.4, and we need to keep that because yum depends on it.
So we first install Python 2.7 as an alternate version of Python:

$ cd ~/code
$ wget https://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz
$ tar xzf Python-2.7.6.tar.gz
$ cd Python-2.7.6
$ ./configure; make -j
$ sudo make altinstall

It’s very important to do make altinstall and not a regular install, because yum depends on Python 2.4. make altinstall will install Python 2.7 as /usr/local/bin/python2.7

Check out latest stable node source

$ cd ~/github
$ git clone git://github.com/joyent/node.git
$ cd node
$ git checkout 0.10.28
$ PYTHON=python2.7 $PYTHON configure
$ make
$ make test

I had a few failing tests. The very first test fails, and takes many seconds to timeout. This is test-abort-fatal-error.js, which seems to be testing the system’s ability to apply resource limits via ulimit. Another test that fails, near the end, is tls-test-server-verify. This sounds ominous, but since I am not planning to use this server in production, I decided to continue.

$ sudo make install

Test node and npm

$ node --version
v0.10.28
$ node
> console.log('Hello, world');
Hello, world
undefined
> ^D

Then create a directory to test npm

$ mkdir test && cd test
$ npm i --save mocha
$ PYTHON=python2.7 npm i --save inchi

Note the explicit setting of the PYTHON environment variable. When installing an npm module that requires compilation (that executes node-gyp), npm will return an error if it runs with the default system python (2.4), since node-gyp requires at least python 2.7. If you install a lot of compiled packages, or it’s painful to remember to set the environment variable PYTHON every time, you can add export PYTHON=python2.7 to your ~/.bash_profile. It doesn’t seem to bother yum.

Inchi, by the way, is an international chemical identifier; specifically, the npm inchi package is javascript interface to the InChI Trust’s C library for converting between structures and InChI codes. Here I’m using it as an example of an npm module that requires compilation and linking to work.

I also noticed that when node-gyp was building

Known Limitations

There are several limitations to this approach.

  1. Test failures making this node 0.10 unsuitable for production

    The ulimit, tls, and flooding tests failed. I would not use this node on a production server that is exposed to DOS attacks.

  2. No support for nvm

    On my production server I use nvm to manage the version of node I’m using. Since nvm downloads prebuilt binaries which link against glibc 2.7, this doesn’t work on CentOS 5

  3. Must rebuild node to get bugfixes / new versions

    Just like in the 1990s, in order to get the next stable version of node, you need to pull the sources and rebuild. This is much easier now, and can even be automated, but it’s a substantial effort that only makes sense if you have no better alternative.

If I can get the tests to build cleanly, I’d be willing to package this up as an RPM for anyone who’s interested.

EDIT: Here’s another approach, written for node 0.8, but will probably work with 0.10. Note that they use EPEL to find and download an RPM for Python 2.6, and a symbolic link from ~/bin/python to /usr/local/bin/python2.6.