ubuntu升级gcc/g++版本
作者:互联网
1. 确认待升级的版本是否存在,若存在,则跳转到第4步
sudo apt-cache search gcc-9
2. 不存在则需要添加 ubuntu toolchain的test源
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
3. 由于默认源在国内速度太慢,建议修改到ustc
# 备份 sudo cp /etc/apt/sources.list.d/ubuntu-toolchain-r-ubuntu-test-bionic.list /etc/apt/sources.list.d/ubuntu-toolchain-r-ubuntu-test-bionic.list.zjr # 修改 cat /etc/apt/sources.list.d/ubuntu-toolchain-r-ubuntu-test-bionic.list #deb http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu bionic main # deb-src http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu bionic main deb https://launchpad.proxy.ustclug.org/ubuntu-toolchain-r/test/ubuntu bionic main # deb-src https://launchpad.proxy.ustclug.org/ubuntu-toolchain-r/test/ubuntu bionic main
4. 升级
sudo apt update sudo apt install gcc-9 g++-9
5. 配置默认gcc/g++ 链接优先级,最后的数字越大优先级越高
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 20 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 20 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 10 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-8 10 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 1 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 1
6. 测试
gcc --version g++ --version
标签:bin,gcc,++,sudo,usr,ubuntu,test 来源: https://www.cnblogs.com/zengjianrong/p/16624273.html