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.

Post filed under Code.

20 Comments

  1. Thanks for this post. It has no doubt saved me from many hours of frustration.

  2. Lorenzouno says:

    Hi,
    This was really helpfull, Thank you very much for this tutorial.

  3. Thanks for the post. Saved my time!

  4. 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:

      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!

  5. Thanks a lot! I was looking for this information for a long time!

  6. NakwangTeag says:

    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.

  7. David Mattei says:

    Thanks man !

  8. 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

  9. Bill Stephenson says:

    I have to offer my thanks too. This work for me on my VPS running CentOS 6.7

  10. Thanks much!!

  11. nacholibre says:

    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.

  12. 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!

  13. JasonYang says:

    Thanks, really help.

  14. Woow…. Thanks a lot!

  15. Made my day!

  16. Many thanks. Worked perfectly.

  17. Mahesh Chavda says:

    Thanks for the post…Saved my time !!

  18. Attila says:

    Thank you so much, you saved my time!!

  19. Ivo Havener says:

    Still valuable over a year later. Thank you for the clear steps.

Leave a Reply to NakwangTeag Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>