1、下载gcc 9.3.0 源码链接: http://ftp.gnu.org/gnu/gcc/gcc-9.3.0/
2、解压
sudo gunzip gcc-9.3.0.tar.gz
sudo tar xvf gcc-9.3.0.tar.gz
3、进入解压缩目录
cd gcc-9.3.0
4、运行download_prerequisites
脚本
./contrib/download_prerequisites
(运行不成功,显示error in server response,运行apt-get install libmpc-dev
安装依赖库)
5、建立输出目录
mkdir gcc-build-9.3.0
cd gcc-build-9.3.0
../configure -enable-checking=release -enable-languages=c,c++ -disable-multilib
6、安装验证
make (需要时间较长) sudo make install gcc -v
7、替换原有GCC
sudo update-alternatives --install /usr/bin/gcc gcc /usr/local/bin/x86_64-pc-linux-gnu-gcc-9.3.0 100
sudo mv /usr/bin/gcc /usr/bin/gcc.bak(给原文件重命名)
sudo ln -s /usr/local/bin/x86_64-pc-linux-gnu-gcc-9.3.0 /usr/bin/gcc
sudo update-alternatives --install /usr/bin/g++ g++ /usr/local/bin/x86_64-pc-linux-gnu-g++ 100
sudo mv /usr/bin/g++ /usr/bin/g++.bak
sudo ln -s /usr/local/bin/x86_64-pc-linux-gnu-g++ /usr/bin/g++