首先下载Gcc-12.2.0.tar.gz数据包:
#cd /usr/local/src
......
#wget https://ftp.gnu.org/gnu/gcc/gcc-12.2.0/gcc-12.2.0.tar.gz
......
解压缩数据包:
#tar xf gcc-12.2.0.tar.gz
......
设置编译环境和选项:
#cd gcc-12.2.0
......
#./contrib /download_prerequisties
......
#mkdir build
......
#cd build
......
#./configure --enable-languages=c,c++ --disable-multilib
......
由于速度较慢,需要耐心等待所有命令完成。
注意:这里使用的是缺省目录项配置。如果对Linux不熟悉,请尽量使用缺省配置。
开始编译和安装:
#make
......
#make install
......
这个过程十分漫长,可能会耗时8个小时左右。需要耐心等待所有命令执行完毕。
先建立一个备份目录,将原有的指令移动到备份目录中。
#mkdir /usr/bin/backup
......
#mv /usr/bin/gcc /usr/bin/backup/
......
#mv /usr/bin/g++ /usr/bin/backup/
......
建立软链接:
#ln -s /usr/local/bin/gcc /usr/bin/gcc
......
#ln -s /usr/local/bin/g++ /usr/bin/g++
......
检查软链接:
# gcc --version
gcc (GCC) 12.2.0
Copyright (C) 2022 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.
......
# g++ --version
g++ (GCC) 12.2.0
Copyright (C) 2022 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版本号。