I'm trying to install the latest stable g++ and c++11. My host did it through yum install and thought that it was the latest, but it's not, and they are now saying that this is beyond their level of support.

I've looked all over on how to do this, and I can't make anything work, or I have no idea what the suggested solution is saying.

What's the easiest way to install g++ 4.7.2 and c++11 on CentOS 5.9?

  • 2
    I don't see anything in that that (in my very inexperienced eyes) requires some new C++ feature. To install extra software (from source, no less) isn't to be taken lightly (if you are using CentOS, it is presumably a enterprisey application). Not for somebody with hours of Linux experience, in any case. Reconsider your options carefully.
    – vonbrand
    Commented Feb 3, 2013 at 22:56
  • 1
    what does require lambda so insistently? Perhaps your best bet is to install latest Fedora, where gcc-4.7.2 is the default compiler, maintained by the distribution?
    – vonbrand
    Commented Feb 3, 2013 at 23:03
  • 2
    I'm no C++ expert, but "sort by N-th int in a vector of int" requires a comparison between vectors, and that is not an exotic requirement only to be fullfilled with latest C++. Sure, it might be easier, but if something that simple couldn't be done from the very first versions of STL, I'd be completely flabbergasted. Get a C++ expert on board?
    – vonbrand
    Commented Feb 3, 2013 at 23:12
  • Have you considered the BOOST libraries? A large percentage of C++11 came from there... Commented Feb 4, 2013 at 0:39
  • c++11 isn't compiler , it's a standard. see my answer. Commented Oct 16, 2013 at 17:12

3 Answers 3


From this answer to "Install gcc 4.7 on CentOS [6.x]", the easiest way to get g++ 4.7, and the required tools and libraries, for CentOS 5.x is via the devtools package:

cd /etc/yum.repos.d
wget http://people.centos.org/tru/devtools/devtools.repo 
yum --enablerepo=testing-devtools-6 install devtoolset-1.0

Since you're running g++ manually (as opposed to through make), you'll need to update your $PATH variable so your shell will use the new gcc, g++, etc. binaries:

export PATH=/opt/centos/devtoolset-1.0/root/usr/bin/:$PATH

At this point, your g++ should be version 4.7.0

$ g++ --version
g++ (GCC) 4.7.0 20120507 (Red Hat 4.7.0-5)
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO

Be aware that installing gcc and associated tools and libraries in this manner relies on the repository maintainer to keep their packages up to date.

If you're interested in keeping your gcc up to date, you may want to consider building gcc from source.

Also, compiling programs with a different version of g++ and libstdc++ than are installed on your system can cause all kinds of Fun, coping with which is beyond the scope of this answer. It may be worth moving to a Linux distribution that has support for what you're doing.

  • I've updated the instructions -- the package you want yum to install is devtoolset-1.0, as that contains other required development tools; and you'll want to update your $PATH variable since you're launching g++ from the command line. Commented Feb 4, 2013 at 0:04
  • When I create a new console, gcc is still on the old version. How do I make the new version the default?
    – B T
    Commented Oct 7, 2015 at 20:05
  • 1
    To set this permanently, you have to add the export PATH.. line in your ~/.profile or ~./profile_bash or equivalent: superuser.com/questions/809250/…
    – B T
    Commented Oct 7, 2015 at 20:14
  • Still shows "g++ (GCC) 4.1.2" after this :-(
    – IS4
    Commented Feb 15, 2017 at 11:10

Package managers are great, but (understandably) won't generally include the latest version of software. CentOS being a distribution particularly focusing on servers, favors stability (and extensive testing) over having the latest and shiniest. Here are your solutions:

Change distro

Other distributions like Arch Linux, Sabayon Linux or Debian "Sid" include newest versions a lot faster. You may consider changing distros.

Build it yourself

If you're stuck with CentOS, your best bet is to build gcc from source. It means getting the source code, making sure the dependencies are already present on your system (if not, I'm sure you can get them from the CentOS package manager), compiling the source into a binary executable, and installing the executable on your system.

It's not the easiest way to do it for sure, but you'll learn a lot about Unix in the process. Make sure to read the document a few times to make sure you get everything, and ask questions if something specific is unclear.

Be patient

At some point, this version (or newer) of gcc/g++ is going to enter the package manager. If you wait (up to several months, I'm not very familiar with the CentOS release cycle), you'll ultimately get what you want.


Hm, I'm too new to comment on Reed's answer. It worked well for me. Only thing I wanted to note (maybe this is something for Reed?) is that I had to install with a slightly different command line:

yum --enablerepo=testing-devtools-5 install devtoolset-1.0

(Reed's answer had --enablerepo=testing-devtools-6, which didn't work.)

You must log in to answer this question.