- 前往GCC官网 下载最新gcc,下载完成后解压安装包:
tar -zxcf gcc-9.2.0.tar.gz
- 获取依赖 GMP,MPFR,MPC
cd gcc-9.2.0
#执行
./contrib/download_prerequisites
- 安装gcc
./configure -enable-checking=release -enable-languages=c,c++ -disable-multilib
make && make install
查看版本信息,如果没有更改则修改环境变量
[root@localhost bin]# gcc --version
gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-23)
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.
- 添加环境变量,否则gcc还是识别旧版本。
vi /etc/profile
#添加:
...
PATH=/usr/local/bin:$PATH
...
#重启profile
source /etc/profile
- 再次检测版本是否变化.
#安装成功
[root@localhost bin]# ./gcc --version
gcc (GCC) 9.2.0
Copyright (C) 2019 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.