CentOS 安装升级GCC4.6.1

分类:CentOS教程 阅读:34536 次

最近由于需求的原因,需要把目前gcc-4.4.4升级到gcc-4.6.1,考虑到有多台的原因,做了一个脚本自动安装结合批量工具分发。

一、安装环境
系统版本:centos6.0X64
原GCC版本:gcc-4.4.4
新GCC版本:gcc-4.6.1

二、正式安装
1、下载安装的源码:

如下需要下载以下包:gcc-4.6.1.tar.bz2 gmp-4.3.2.tar.bz2 mpc-0.8.1.tar.gz mpfr-2.4.2.tar.bz2 下载地址如下: wget ftp://gcc.gnu.org/pub/gcc/infrastructure/{gmp-4.3.2.tar.bz2,mpc-0.8.1.tar.gz,mpfr-2.4.2.tar.bz2} wget http://ftp.gnu.org/gnu/gcc/gcc-4.6.1/gcc-4.6.1.tar.bz2 即可!


2、解压安装:安装有先后顺序:GMP、MPFR、MPC、GCC

安装GMP: tar jxf gmp-4.3.2.tar.bz2 &&cd gmp-4.3.2/ ;./configure ?prefix=/usr/local/gmp/ &&make &&make install 

安装MPFR:

cd ../ ;tar jxf mpfr-2.4.2.tar.bz2 ;cd mpfr-2.4.2/ ;./configure ?prefix=/usr/local/mpfr ?with-gmp=/usr/local/gmp &&make &&make install 

安装MPC:

cd ../ ;tar xzf mpc-0.8.1.tar.gz ;cd mpc-0.8.1 ;./configure ?prefix=/usr/local/mpc ?with-mpfr=/usr/local/mpfr ?with-gmp=/usr/local/gmp &&make &&make install 

安装GCC:

cd ../ ;tar jxf gcc-4.6.1.tar.bz2 ;cd gcc-4.6.1 ;./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 

然后执行如下:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc/lib:/usr/local/gmp/lib:/usr/local/mpfr/lib/ 

//这一步很关键,设置变量,不设置后面会报错。

make && make install 安装完毕即可!然后做一个链接就可以使用GCC了 mkdir -p /data/backup/`date +%Y%m%d` mv /usr/bin/{gcc,g++} /data/backup/`date +%Y%m%d` 新建软链接: ln -s /usr/local/gcc/bin/gcc /usr/bin/gcc ln -s /usr/local/gcc/bin/g++ /usr/bin/g++ 

三、测试GCC
直接输入gcc -v 可以查看到gcc 版本为4.6.1和相关的编译参数就ok了!附上一个最简单的安装脚本:

#!/bin/sh ##auto make install gcc ##2012-07-03 tar jxf gmp-4.3.2.tar.bz2 &&cd gmp-4.3.2/ ;./configure ?prefix=/usr/local/gmp/ &&make &&make install sleep 1 cd ../ ;tar jxf mpfr-2.4.2.tar.bz2 ;cd mpfr-2.4.2/ ;./configure ?prefix=/usr/local/mpfr ?with-gmp=/usr/local/gmp &&make &&make install cd ../ ;tar xzf mpc-0.8.1.tar.gz ;cd mpc-0.8.1 ;./configure ?prefix=/usr/local/mpc ?with-mpfr=/usr/local/mpfr ?with-gmp=/usr/local/gmp &&make &&make install cd ../ ;tar jxf gcc-4.6.1.tar.bz2 ;cd gcc-4.6.1 ;./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/ if [ $? -eq 0 ];then echo “This gcc configure is success” else echo “This gcc configure is failed” fi export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc/lib:/usr/local/gmp/lib:/usr/local/mpfr/lib/ make && make install [ $? -eq 0 ]&&echo This is make install success