October 05, 2021

set default gcc, cpp, clang versions in Debian 11, Debian 12 Linux

edit: updated this for Debian 12 / gcc 12, but essentially same solution(s).
see also: https://apt.llvm.org/

Problem: cpp-10 is default in Debian 11

Need: cpp-9 or gcc-9 as default

Solution:


sudo apt install build-essential cpp-12 cpp-11 cpp-10 cpp-9 gcc-12 gcc-11 gcc-10 gcc-9 

sudo update-alternatives --install /usr/bin/cpp cpp /usr/bin/cpp-9 10
sudo update-alternatives --install /usr/bin/cpp cpp /usr/bin/cpp-10 20
sudo update-alternatives --install /usr/bin/cpp cpp /usr/bin/cpp-11 30
sudo update-alternatives --install /usr/bin/cpp cpp /usr/bin/cpp-12 40

update-alternatives --query cpp
sudo update-alternatives --config cpp

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 10
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 20
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 30
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 40

update-alternatives --query gcc
sudo update-alternatives --config gcc

Resource: https://stackoverflow.com/questions/7832892/how-to-change-the-default-gcc-compiler-in-ubuntu

Potential problems:
If you get something like update-alternatives: error: cannot stat file '/usr/bin/cpp': Too many levels of symbolic links, then sudo rm /etc/alternatives/cpp. BUT be sure to reinstall cpp-* to get the /user/bin links recreated.




And you may do similarly with Clang/Clang++

sudo apt install clang-14 clang-13 clang-12 clang-11

sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-11 10
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-12 20
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-13 30
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-14 40

sudo update-alternatives --config clang

sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-11 10
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-12 20
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-13 30
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-14 40

sudo update-alternatives --config clang++


If you prefer non-interactive config, then you may

sudo update-alternatives --set clang /usr/bin/clang-12
sudo update-alternatives --set clang++ /usr/bin/clang++-12
and do so silimarly for any other alternatives







~~
good luck!

Written with StackEdit.

SEO:
cpp gcc 9 10 default Debian Linux Ubuntu RHEL CentOS Fedora Arch Mint


Please consider crypto tipping:
  

No comments:

Post a Comment

Comments, Suggestions or "Thank you's" Invited! If you have used this info in any way, please comment below and link/link-back to your project (if applicable). Please Share.
I accept Bitcoin tips of ANY amount to: 1GS3XWJCTWU7fnM4vfzerrVAxmnMFnhysL
I accept Litecoin tips of ANY amount to: LTBvVxRdv2Lz9T41UzqNrAVVNw4wz3kKYk