[Centos]升级安装GCC
摘要
在尝试运行asp.net core站点的时候,发现了gcc包版本太低,造成一些错误。没办法只能升级gcc了。
升级
最新包:http://gcc.parentingamerica.com/releases/gcc-6.2.0/gcc-6.2.0.tar.bz2
下载
wget http://gcc.parentingamerica.com/releases/gcc-6.2.0/gcc-6.2.0.tar.bz2
gcc
安装文件下载完成后,执行以下命令解压文件:
tar -xf gcc-6.2.0.tar.bz2
下载gcc依赖库和文件
解压完成后,执行以下命令进入工作目录:
cd gcc-6.2.0
执行download_prerequisites
脚本,下载gcc
依赖文件和库:
./contrib/download_prerequisites
ownload_prerequisites
脚本,会下载安装gcc
所需的mpfr
、gmp
和mpc
文件。
[root@localhost gcc-6.2.0]# ./contrib/download_prerequisites --2016-11-23 19:35:16-- ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-2.4.2.tar.bz2 => “mpfr-2.4.2.tar.bz2” Resolving gcc.gnu.org... 209.132.180.131 Connecting to gcc.gnu.org|209.132.180.131|:21... connected. Logging in as anonymous ... Logged in! ==> SYST ... done. ==> PWD ... done. ==> TYPE I ... done. ==> CWD (1) /pub/gcc/infrastructure ... done. ==> SIZE mpfr-2.4.2.tar.bz2 ... 1077886 ==> PASV ... done. ==> RETR mpfr-2.4.2.tar.bz2 ... done. Length: 1077886 (1.0M) (unauthoritative) 100%[==========================================================>] 1,077,886 62.6K/s in 24s 2016-11-23 19:35:48 (44.3 KB/s) - “mpfr-2.4.2.tar.bz2” saved [1077886] --2016-11-23 19:35:49-- ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-4.3.2.tar.bz2 => “gmp-4.3.2.tar.bz2” Resolving gcc.gnu.org... 209.132.180.131 Connecting to gcc.gnu.org|209.132.180.131|:21... connected. Logging in as anonymous ... Logged in! ==> SYST ... done. ==> PWD ... done. ==> TYPE I ... done. ==> CWD (1) /pub/gcc/infrastructure ... done. ==> SIZE gmp-4.3.2.tar.bz2 ... 1897483 ==> PASV ... done. ==> RETR gmp-4.3.2.tar.bz2 ... done. Length: 1897483 (1.8M) (unauthoritative) 100%[==========================================================>] 1,897,483 21.5K/s in 92s 2016-11-23 19:37:28 (20.2 KB/s) - “gmp-4.3.2.tar.bz2” saved [1897483] --2016-11-23 19:37:29-- ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-0.8.1.tar.gz => “mpc-0.8.1.tar.gz” Resolving gcc.gnu.org... 209.132.180.131 Connecting to gcc.gnu.org|209.132.180.131|:21... connected. Logging in as anonymous ... Logged in! ==> SYST ... done. ==> PWD ... done. ==> TYPE I ... done. ==> CWD (1) /pub/gcc/infrastructure ... done. ==> SIZE mpc-0.8.1.tar.gz ... 544950 ==> PASV ... done. ==> RETR mpc-0.8.1.tar.gz ... done. Length: 544950 (532K) (unauthoritative) 100%[==========================================================>] 544,950 24.5K/s in 19s 2016-11-23 19:37:55 (27.7 KB/s) - “mpc-0.8.1.tar.gz” saved [544950] --2016-11-23 19:37:55-- ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.15.tar.bz2 => “isl-0.15.tar.bz2” Resolving gcc.gnu.org... 209.132.180.131 Connecting to gcc.gnu.org|209.132.180.131|:21... connected. Logging in as anonymous ... Logged in! ==> SYST ... done. ==> PWD ... done. ==> TYPE I ... done. ==> CWD (1) /pub/gcc/infrastructure ... done. ==> SIZE isl-0.15.tar.bz2 ... 1574964 ==> PASV ... done. ==> RETR isl-0.15.tar.bz2 ... done. Length: 1574964 (1.5M) (unauthoritative) 100%[==========================================================>] 1,574,964 44.3K/s in 30s 2016-11-23 19:38:30 (51.4 KB/s) - “isl-0.15.tar.bz2” saved [1574964] [root@localhost gcc-6.2.0]#
配置gcc
建立一个输出目录,编译时所有生成的中间文件都放到该目录下:
mkdir gcc-temp
工作目录切换至输出目录,并在其中执行配置和安装:
cd gcc-temp
执行configure
配置安装文件:
../configure --enable-checking=release --enable-languages=c,c++ --disable-multilib
配置完成后,执行以下命令,编译gcc
:
make
编译过程较长,耐心等待。编译完成后,安装gcc
:
make install
安装完成后还需要替换系统默认的gcc
,执行以下命令,查找6.2
版本的安装文件:
ls /usr/local/bin | grep gcc
执行升级命令:
/usr/sbin/update-alternatives --install /usr/bin/gcc gcc /usr/local/bin/x86_64-pc-linux-gnu-gcc-6.2.0 52
验证安装
查看版本号
gcc -v
到此说明安装成功了。
参考文章
-
博客地址:http://www.cnblogs.com/wolf-sun/
博客版权:如果文中有不妥或者错误的地方还望高手的你指出,以免误人子弟。如果觉得本文对你有所帮助不如【推荐】一下!如果你有更好的建议,不如留言一起讨论,共同进步! 再次感谢您耐心的读完本篇文章。