在 Ubuntu 18.04 上安装 gcc 5

sin*_*ium 12 compiling gcc 18.04

gcc 7.3.0在 Ubuntu 18.04 上。但是我正在开发一个需要低于版本 6 的 gcc 的项目。当我尝试使用 安装 gcc 5.4 时sudo apt install gcc-5.4,出现此错误:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package gcc-5.4
E: Couldn't find any package by glob 'gcc-5.4'
E: Couldn't find any package by regex 'gcc-5.4'  
Run Code Online (Sandbox Code Playgroud)

安装 gcc 5.4 的合适方法是什么?

sin*_*ium 10

感谢@steeldriver,我可以解决以下问题:

安装 gcc 和 g++

sudo apt install g++-5
sudo apt install gcc-5
Run Code Online (Sandbox Code Playgroud)

将符号链接更改为指向 gcc 5 和 g++ 5

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 10
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 20
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30
sudo update-alternatives --set cc /usr/bin/gcc
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30
sudo update-alternatives --set c++ /usr/bin/g++
Run Code Online (Sandbox Code Playgroud)

积分: 如何选择默认的 gcc 和 g++ 版本?