ubuntu 卸载 gcc g++ 软件重新添加 gcc11 g++11(其他版本号类似)具体操作步骤
1 卸载原本的gcc和g++
2 添加旧版本源文件
3 安装新版本gcc和g++
4 指定版本号
5 查看版本号
1 卸载原本的gcc和g++
sudo apt remove --purge gcc g++ -y
# 删除gcc和g++文件
sudo apt autoremove -y
sudo apt clean
2 添加旧版本源文件
确保已添加适用于 Ubuntu 系统的官方软件源(如 ppa:ubuntu-toolchain-r/test)
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
sudo apt update
3 安装新版本gcc和g++
sudo apt install gcc-11 g++-11 -y
# 添加gcc和g++
4 指定版本号
由于之前安装工gcc和g++但是没有将文件路径卸载完全,所以需要手动指定版本号
# 选择版本号
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 100
# 更新指定路径
sudo update-alternatives --config gcc
sudo update-alternatives --config g++
5 查看版本号
gcc --version
g++ --version
亲测有效!