- 检查是否已经安装了GCC以及GCC版本
[root@localhost ~]# gcc -v
查看已安装的gcc版本,如果提示未找到命令,则未安装gcc。
上图中可以看到系统已经安装了GCC 4.8.5,由于存在很多依耐性,我们手动安装更高版本
- 选择需要安装的gcc更高版本并下载
gcc FTP下载地址
此处选择gcc 6.4.0
[root@localhost ~]# wget https://ftp.gnu.org/gnu/gcc/gcc-6.4.0/gcc-6.4.0.tar.gz
- 解压安装包
[root@localhost ~]# tar -zxvf gcc-6.4.0.tar.gz
- 进入解压后的gcc源码文件夹,下载供编译的依赖项,
[root@localhost ~]# cd gcc-6.4.0
[root@localhost gcc-6.4.0]# ./contrib/download_prerequisites
- 生成Makefile文件
注意,如果不使用–disable-multilib参数,在生成Makefile过程中会报错
configure: error: I suspect your system does not have 32-bit
development libraries (libc and headers). If you have them, rerun
configure with --enable-multilib. If you do not have them, and want to
build a 64-bit-only compiler, rerun configure with --disable-multilib.
系统统没有32位开发支持库,可以运行yum install glibc-devel.i686安装,不过我这里不需要编译32位程序,所以使用–disable-multilib参数
[root@localhost gcc-6.4.0]# ./configure --disable-multilib
- 编译并安装
[root@localhost gcc-6.4.0]# make && make install
- 重启服务器并验证GCC版本
[root@localhost ~]# gcc -v