下载gcc
ftp://gcc.gnu.org/pub/gcc/releases/

下载相关倚赖
ftp://gcc.gnu.org/pub/gcc/infrastructure/

若编译安装时直接报编译路径错误,那么就要先安装个默认版本的gcc
yum install gcc

安装GMP4.3.2:
./configure –prefix=/usr/local/gmp && make && make install

安装MPFR2.4.2
./configure –prefix=/usr/local/mpfr –with-gmp=/usr/local/gmp && make && make install

安装MPC0.8.1
./configure –prefix=/usr/local/mpc –with-mpfr=/usr/local/mpfr –with-gmp=/usr/local/gmp && make && make install

安装GCC4.6.3
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc/lib:/usr/local/gmp/lib:/usr/local/mpfr/lib/

./configure –prefix=/usr/local/gcc –enable-threads=posix –disable-checking –disable-multilib –enable-languages=c,c++ –with-gmp=/usr/local/gmp –with-mpfr=/usr/local/mpfr/ –with-mpc=/usr/local/mpc/ && make && make install

至此,安装gcc4.6.3完毕.

————————–
下面设置环境变量:
vi /etc/profile
export GCC_HOME=/usr/local/gcc
export CPLUS_INCLUDE_PATH=$GCC_HOME/include:$GCC_HOME/include/c++/4.6.3
export LIBRARY_PATH=/usr/local/gmp/lib:/usr/local/mpfr/lib:/usr/local/mpc/lib:$GCC_HOME/lib64:$GCC_HOME/lib:$GCC_HOME/lib/gcc/x86_64-unknown-linux-gnu/4.6.3
export LD_LIBRARY_PATH=/usr/local/gmp/lib:/usr/local/mpfr/lib:/usr/local/mpc/lib:$GCC_HOME/lib64:$GCC_HOME/lib:$GCC_HOME/lib/gcc/x86_64-unknown-linux-gnu/4.6.3
export PATH=$GCC_HOME/bin:$PATH

或者(不推荐)
mv /usr/bin/gcc /usr/bin/gcc.bak
ln -s /usr/local/gcc/bin/gcc /usr/bin/gcc
mv /usr/bin/g++ /usr/bin/g++.bak
ln -s /usr/local/gcc/bin/g++ /usr/bin/g++
mv /usr/bin/c++ /usr/bin/c++.bak
ln -s /usr/local/gcc/bin/c++ /usr/bin/c++
mv /usr/bin/cpp /usr/bin/cpp.bak
ln -s /usr/local/gcc/bin/cpp /usr/bin/cpp
mv /usr/bin/gcov /usr/bin/gcov.bak
ln -s /usr/local/gcc/bin/gcov /usr/bin/gcov

或者
alternatives –install <link> <name> <path> <priority>
其中,
install表示安装
link是符号链接
name则是标识符
path是执行文件的路径
priority则表示优先级

alternatives –install /usr/bin/gcc gcc /usr/local/gcc/bin/gcc 2
alternatives –config gcc
选择2