如何在Ubuntu 17.10上安装GCC 5.4(降级操作)
Hey there, let's fix this GCC downgrade issue for your Ubuntu 17.10 system. The root problem here is that Ubuntu's package repository doesn't use the full minor version (like gcc-5.4) as the package name—instead, it uses the major version (gcc-5), which includes the 5.4.0 release you need. Here's how to get it working:
步骤1:更新软件源缓存
First, make sure your package list is up to date so the system can find the correct GCC packages:
sudo apt update
步骤2:安装GCC 5(对应5.4.0版本)
Instead of trying to install gcc-5.4, install the gcc-5 and g++-5 packages—these will pull down the 5.4.0 release for Ubuntu 17.10:
sudo apt install gcc-5 g++-5
步骤3:设置默认GCC版本为5.4
Now you have both GCC 7 and GCC 5 on your system. Use update-alternatives to configure GCC 5 as the default:
- Add GCC alternatives with priority levels (higher number = higher priority):
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 100 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 50 - Do the same for G++:
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 100 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 50
步骤4:验证切换结果
Check if the default version has changed successfully:
gcc --version g++ --version
You should see output showing gcc (Ubuntu 5.4.0-6ubuntu1~17.10.1) 5.4.0 20160609 or similar.
额外提示:切换回GCC 7(如果需要)
If you ever need to switch back to GCC 7 later, just run:
sudo update-alternatives --config gcc
Then select the number corresponding to gcc-7 from the list. Repeat the same command for g++ if needed.
内容的提问来源于stack exchange,提问作者jonb

