Ubuntu20使用apt安装gcc-5(使用Ubuntu阿里云镜像)
添加 xenial
到 /etc/apt/sources.list
参考 https://askubuntu.com/questions/1235819/ubuntu-20-04-gcc-version-lower-than-gcc-7 这篇文章,
核心是 Add
xenial
to /etc/apt/sources.list
但是,我之前参考 https://developer.aliyun.com/mirror/ubuntu?spm=a2c6h.13651102.0.0.3e221b11BmMBfZ 配置过国内镜像
所以,sudo vim /etc/apt/sources.list
内容是这样的:
deb https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
# deb https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
然后,我就在文件末尾追加了:
deb https://mirrors.aliyun.com/ubuntu/ xenial main
deb-src https://mirrors.aliyun.com/ubuntu/ xenial main
deb https://mirrors.aliyun.com/ubuntu/ xenial universe
deb-src https://mirrors.aliyun.com/ubuntu/ xenial universe
xenial 这个选项在 ubuntu 16.04 配置下是默认的
安装gcc-5
接下来就可以顺利执行一下安装命令了
geekziyu@geekziyu-ubuntu-1:~$ sudo apt update
geekziyu@geekziyu-ubuntu-1:~$ sudo apt install g++-5 gcc-5
切换GCC默认版本到gcc-5
geekziyu@geekziyu-ubuntu-1:~$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 5
geekziyu@geekziyu-ubuntu-1:~$ sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 5
如果有多个gcc版本,输入以下命令,再输入数字手动配置正确的 gcc/g++ 版本
geekziyu@geekziyu-ubuntu-1:~$ sudo update-alternatives --config gcc
geekziyu@geekziyu-ubuntu-1:~$ sudo update-alternatives --config g++
最后使用 gcc -v
和 g++ -v
查看当前版本是否正确