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:
wget https://nodejs.org/dist/latest/node-v4.0.0.tar.xz
tar Jxf node-v4.0.0.tar.xz
cd node-v4.0.0
./configure
make
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.
Goran says:
September 14, 2015 at 16:54 /
Thanks for this post. It has no doubt saved me from many hours of frustration.
Lorenzouno says:
September 16, 2015 at 01:24 /
Hi,
This was really helpfull, Thank you very much for this tutorial.
Veaceslav says:
September 16, 2015 at 14:09 /
Thanks for the post. Saved my time!
Thomas says:
September 17, 2015 at 08:41 /
Hello,
I wanted to let you know that part of your URL on the page is being covered up. This URL:
http://ftp.mirrorservice.org/sites/ftp.scientificlinux.org/linux/scientific/51/i386/RPM-GPG-KEYs/RPM-GPG-KEY-cern
“i386/RPM-” is being covered up by the Categories on the right. I was only able to figure this out, because I
right-clicked -> inspect element
and saw the actual text.
krisreeves says:
October 23, 2015 at 07:20 /
Sorry about that, I hadn’t actually expected (m)any comments and I never came back and approved/checked them! I actually just came back to my site to follow my own instructions just now, but didn’t experience this problem. I imagine the theme doesn’t adapt well to different layouts. I think this comment should be enough to help any others who run into this work it out until I have a chance to try and fix the theme to be better or update it.
Edit: I modified the paragraphs to scroll horizontally and the code blocks not to wrap so it’s clear where the newlines are. Hopefully that helps!
Jose says:
September 25, 2015 at 15:21 /
Thanks a lot! I was looking for this information for a long time!
NakwangTeag says:
October 1, 2015 at 17:57 /
I was also saddened to see this:
WARNING: C++ compiler too old, need g++ 4.8 or clang++ 3.4 (CXX=g++)
in Raspberry Pi2 used Raspin linux.
How can I have correcting load.
David Mattei says:
October 8, 2015 at 08:10 /
Thanks man !
Nate says:
October 16, 2015 at 10:10 /
Thanks so much for this – absolute life saver! Limited VPS exposure meant when NPM failed install i was worried how i was going to fix it. So handy to install Bower to readily install other bits and bobs. Thanks
Bill Stephenson says:
October 28, 2015 at 20:58 /
I have to offer my thanks too. This work for me on my VPS running CentOS 6.7
Visu says:
November 4, 2015 at 23:16 /
Thanks much!!
nacholibre says:
November 5, 2015 at 06:21 /
yum has clang 3.4.2, so you do yum install clang and before compiling you type
export CXX=clang
and the configure…, no need to install newer version of gcc.
tcdw says:
November 19, 2015 at 08:06 /
I am really delighted when I see your post.
I finally solved my problem when I install Node.js 5.0 on my CentOS 6.5 machine.
Great job you get here!
JasonYang says:
November 22, 2015 at 18:01 /
Thanks, really help.
Carlos says:
January 19, 2016 at 22:11 /
Woow…. Thanks a lot!
Hans S. says:
February 26, 2016 at 16:55 /
Made my day!
TC says:
March 2, 2016 at 15:48 /
Many thanks. Worked perfectly.
Mahesh Chavda says:
July 6, 2016 at 08:29 /
Thanks for the post…Saved my time !!
Attila says:
July 28, 2016 at 11:28 /
Thank you so much, you saved my time!!
Ivo Havener says:
December 8, 2016 at 13:14 /
Still valuable over a year later. Thank you for the clear steps.
Ben says:
July 13, 2017 at 11:51 /
Thanks for this article, still relevant for CentOS 6 users.
I found the the url no longer works, I had to get the repo this way:
wget -O /etc/yum.repos.d/slc6-devtoolset.repo http://linuxsoft.cern.ch/cern/devtoolset/slc6-devtoolset.repo
I also had to run the yum install line with nogpgcheck as it was erroring:
yum install –nogpgcheck devtoolset-3
krisreeves says:
July 13, 2017 at 17:45 /
Thanks for the tip! This is pretty out of date now, but I’m glad it still generally helps.
I’d recommend finding and installing the correct keys as opposed to disabling checking them altogether, but I no longer have access to a machine with this distro to really work it out with…