DEV Community

nullity
nullity

Posted on • Edited on

Install or uninstall gcc 13 on Ubuntu 20.04

Testing date: Mar 14, 2024

Install gcc-13, g++-13

sudo apt update
sudo apt install software-properties-common

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt update
sudo apt install gcc-13 g++-13
Enter fullscreen mode Exit fullscreen mode

Add gcc-13 to gcc's alternatives

並設定 "切換 gcc 版本時會同時切換 g++, gcov 的版本"
At the time, the latest gcc provided by this ppa is 13.1

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 131 --slave /usr/bin/g++ g++ /usr/bin/g++-13 --slave /usr/bin/gcov gcov /usr/bin/gcov-13
Enter fullscreen mode Exit fullscreen mode

若之前沒有設定過 priority 大於 131 的 gcc 版本,則此時的 gcc 版本會自動切換至 gcc-13

Check gcc's version

At the time, the latest gcc provided by this ppa is 13.1

gcc -v
Enter fullscreen mode Exit fullscreen mode

Uninstall gcc 13

sudo update-alternatives --remove gcc /usr/bin/gcc-13
sudo apt purge gcc-13 g++-13
Enter fullscreen mode Exit fullscreen mode

ref

Top comments (0)