How to install g++ 4.9.2 in Cent OS 6.5?

I am trying to install the latest version of g++ in Cent OS. The best I managed is the following:

wget http://people.centos.org/tru/devtools-2/devtools-2.repo -O /etc/yum.repos.d/devtools-2.repo
yum install devtoolset-2-gcc devtoolset-2-binutils
yum install devtoolset-2-gcc-c++ devtoolset-2-binutils

But this installs g++ 4.8.2 and not 4.9.2. Is there a way to install 4.9.2?


Solution 1:

You will have to do it the old fashioned way. Get the GCC sources, build it by hand.

Any reason you are averse to doing this? (I can think of a few, but unless you do too, I don't want to add anything that might be confusing).

If you are hesitant to build from sources, I can probably provide some steps.

NOTE: The reason for that is the devtools with 4.9 is currently only available to Red Hat users with a valid license. Wait for a while, and eventually I am sure 4.9 devtools will be made available to CentOS users too like 4.8 is currently.

Solution 2:

CentOS 6/7 officially supports this. You don't need third party repository. And gcc version is 4.9.2 in CentOS's repo.

yum install centos-release-scl-rh          
yum install devtoolset-3-gcc devtoolset-3-gcc-c++   

To use the updated tools, start a new shell using the scl command:

scl enable devtoolset-3 bash

You may also need to reset your PATH environment variable, which might be set in ~/.bashrc or other profile file. If you need to change it, it should point to /opt/rh/devtoolset-3/root/usr/bin/:$PATH

More information on the SCL from CentOS and from Red Hat

Solution 3:

I use Scientific Linux Cern 6 repository to install gcc 4.9 and g++ 4.9 on my CentOS 6.5 and CentOS 6.6 systems. It does not install g++ 4.9.2. It installs g++ 4.9.1 instead which is good enough for my needs.

Here are the commands I use to install it.

cd /etc/yum.repos.d
wget http://linuxsoft.cern.ch/cern/scl/slc6-scl.repo
yum -y --nogpgcheck install devtoolset-3-gcc devtoolset-3-gcc-c++

As Michael said in his comment to this post, to actually use the version of gcc that this installs, start a new shell with the following command.

scl enable devtoolset-3 bash