CentOS is great because it is secure, but not great because it doesn’t have the latest software. Here is how to install C++11 on CentOS6 or CentOS7, and temporarily activate it in a shell. This does not change the default compiler and should cause less problems with your system (but that is not a money back guarantee … you are own your own if it does!)
Check your current C++ version:
# gcc --version gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28) Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Install the scl release:
# yum install centos-release-scl
Upgrade, and then check the available devtool set versions.
# yum upgrade # yum list all | grep devtoolset
When I did this it was still on devtoolset-7, so I installed that version:
# yum install -y devtoolset-7
Now check your C++ version again:
# gcc --version gcc (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5) Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Note: The commands below worked for CentOS6 and devtoolset-2. The commands above should work, but these remain here for historic reference.
Check your current C++ version:
# gcc --version gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-16) Copyright (C) 2010 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
If you are using gcc version 4.4, you don’t have C++11. You need to update to gcc version 4.8. However, we don’t want to update the default gcc installation because that will break everything. So we install the development libraries and use software control to switch in this shell.
Install the devo repo:
wget http://people.centos.org/tru/devtools-2/devtools-2.repo -O /etc/yum.repos.d/devtools-2.repo
Once you have installed that, do an upgrade on yum:
yum upgrade
Next, install C++11
yum install devtoolset-2-gcc devtoolset-2-binutils devtoolset-2-gcc-c++
Finally, use the software collections to enable it in the current shell:
scl enable devtoolset-2 bash
Check the version again:
# gcc --version gcc (GCC) 4.8.2 20140120 (Red Hat 4.8.2-15) Copyright (C) 2013 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
When you log out, you will be using the default system version.
If you install other toolsets (RedHat is now upto devtoolset-7), you can list all the installed software collections using -l:
scl -l