Ubuntu中gcc降低版本

655 阅读1分钟

ubuntu22.10安装低版本gcc/g++

1. 查看当前版本

gcc -v
g++ -v

2. 添加软件源

sudo gedit /etc/apt/sources.list

#在文尾添加

deb http://dk.archive.ubuntu.com/ubuntu/ xenial main
deb http://dk.archive.ubuntu.com/ubuntu/ xenial universe

#更新
sudo apt-get update

3. 安装gcc5,g++5

sudo apt-get install g++-5 gcc-5

如果没有办法安装就继续换源

4. 查看

ls /usr/bin/gcc*
ls /usr/bin/g++*

image.png

5. 设置优先级

5.1 改gcc5为默认版本

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 40
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 50
sudo update-alternatives --config gcc

#选择gcc-5对应的编号回车即可

5.2 改g++5为默认版本

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/g++-5 40
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/g++-12 50
sudo update-alternatives --config gcc

#选择g++-5对应的编号回车即可