Node.js 4.0 just came out, but since I’m forced to operate on a CentOS machine I was saddened to see this:
WARNING: C++ compiler too old, need g++ 4.8 or clang++ 3.4 (CXX=g++)
…when attempting to configure. (I learned long ago that yum wasn’t the way to go with Node. There are also problems with older versions of CentOS since Node requires Python 2.7, but that’s not what this post is for…)
With great regret, I set about figuring out how to install (read: build) newer compiler tools for a distribution that is very slow to change, but lo! I was pleasantly surprised to find out that Scientific Linux had me covered!
All you have to do to get a modern version of G++ is:
sudo curl http://linuxsoft.cern.ch/cern/scl/slc6-scl.repo > /etc/yum.repos.d/slc6-scl.repo
sudo rpm --import http://ftp.mirrorservice.org/sites/ftp.scientificlinux.org/linux/scientific/51/i386/RPM-GPG-KEYs/RPM-GPG-KEY-cern
sudo yum install -y devtoolset-3
And to utilize it without having to set environment variables:
scl enable devtoolset-3 bash
Presto! You have a shell with access to G++ 4.9 and Node.js is happy. For completeness, here’s what to do to compile it:
tar Jxf node-v4.0.0.tar.xz
sudo make install
You’ll note I favored the .xz because I learned (to my pleasant surprise) that it was supported, but if you have some problem there’s always the .tar.gz too.
Just wanted to get these instructions out there in one place so people in my situation have an easy reference answer. Have fun!
P.S. – For me, `make install` resulted in a mode 700 binary, which meant I couldn’t run it as a user:
-bash: /usr/local/bin/node: Permission denied
This seems to be a bug or problem in the Makefile, but is easily remedied:
sudo su - -c 'chmod +rx $(which node)'
It also looks like node is being installed to a new location, so if you’re in the habit of installing “over the top” of previous versions, you may want to `make uninstall` them first to clean up.