update yum config via vi:
$ vi /etc/yum.repos.d/DevToolset.repo
make sure this file is new and paste below block to your terminal:
[DevToolset-2]
name=RedHat DevToolset v2 $releasever - $basearch
baseurl=http://puias.princeton.edu/data/puias/DevToolset/$releasever/$basearch/
enabled=1
gpgcheck=0
install gcc 4.8.1:
$ yum install devtoolset-2-gcc-4.8.1 devtoolset-2-gcc-c++-4.8.1
$ /opt/rh/devtoolset-2/root/usr/bin/gcc --version
> gcc (GCC) 4.8.1 20130715 (Red Hat 4.8.1-4)
create link let you just simplely run gcc
:
$ ln -s /opt/rh/devtoolset-2/root/usr/bin/* /usr/local/bin/
$ hash -r
$ gcc --version
> gcc (GCC) 4.8.1 20130715 (Red Hat 4.8.1-4)
This tutorial is inspired by http://superuser.com/questions/381160/how-to-install-gcc-4-7-x-4-8-x-on-centos, thank you the author :)