Clang is not a version of GCC, so it cannot be set as an alternative for /usr/bin/gcc. Don't try to override this; you will break some programs which require GCC-specific features which aren't available in Clang.

Clang can be set as an alternative for /usr/bin/cc. This is the standard way of setting a C compiler, and it should be reasonably safe. (Even so, I wouldn't be surprised if some build processes break due to an assumption that /usr/bin/cc on a Linux system is always GCC.)

Answer from user149341 on Stack Overflow
🌐
GitHub
gist.github.com › junkdog › 70231d6953592cd6f27def59fe19e50d
update-alternatives-clang.sh - Gist - GitHub
This is on Ubuntu 22.04+ Builds Linux kernel with LTO. #!/usr/bin/env bash # --slave /usr/bin/$1 $1 /usr/bin/$1-\${version} \\ function register_clang_version { local version=$1 local priority=$2 update-alternatives \ --verbose \ --install /usr/bin/llvm-config llvm-config /usr/bin/llvm-config-${version} ${priority} \ --slave /usr/bin/llvm-ar llvm-ar /usr/bin/llvm-ar-${version} \ --slave /usr/bin/llvm-as llvm-as /usr/bin/llvm-as-${version} \ --slave /usr/bin/llvm-bcanalyzer llvm-bcanalyzer /usr/bin/llvm-bcanalyzer-${version} \ --slave /usr/bin/llvm-c-test llvm-c-test /usr/bin/llvm-c-test-${vers
🌐
Egli
egli.dev › posts › update-alternatives-for-clang-format
Switch between different versions of clang-format • egli.dev
Then add a new group named clang-format to the alternatives system. You can do that manually or use the small script below: #!/usr/bin/env bash BINARY=/usr/bin/clang-format MANPAGE=/usr/share/man/man1/clang-format function register_clang_format_version { local version=$1 local priority=$2 update-alternatives \ --install ${BINARY} clang-format ${BINARY}-${version} ${priority} \ --slave ${MANPAGE}.1.gz clang-format.1.gz ${MANPAGE}-${version}.1.gz } register_clang_format_version 10 100 register_clang_format_version 9 20 register_clang_format_version 8 10 register_clang_format_version 7 50
Top answer
1 of 2
26

These work for me:

sudo update-alternatives --install /usr/bin/cc cc /usr/bin/clang-3.6 100
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++-3.6 100
2 of 2
14

Since clang is referenced directly as well as via cc, I would break this up into alternatives for clang, and alternatives for cc. After clang is set up below:

sudo update-alternatives --install /usr/bin/cc cc /usr/bin/clang 100
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++ 100

To select the version of clang, and cc:

sudo update-alternatives --config clang
sudo update-alternatives --config clang++
sudo update-alternatives --config cc
sudo update-alternatives --config c++

Setting up clang/clang++. Multiple versions of clang are packaged with Ubuntu. In 15.10, for example:

clang-3.4 - C, C++ and Objective-C compiler (LLVM based)
clang-3.5 - C, C++ and Objective-C compiler (LLVM based)
clang-3.6 - C, C++ and Objective-C compiler (LLVM based)
clang-3.7 - C, C++ and Objective-C compiler (LLVM based)

The highest priority alternative is auto, and the rest are manually selected. So if my default were to be the latest, and 4 versions were installed:

sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.7 370
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.7 370
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.6 360
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.6 360
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.5 350
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.5 350
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.4 340
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.4 340

If you apply the same to LLDB, you have a fairly complete development environment that includes cross-compilers/debuggers for several architectures. ('fairly' means that the linker, LLD, is not quite mature enough to say complete).

Note: LLDB + Python-LLDB are needed for a complete debugger. Multiple versions of python-lldb CANNOT be installed together, so the best option at this point is to pick the latest version of LLDB with it's associated python package.

🌐
UbuntuHandbook
ubuntuhandbook.org › home › howtos › install clang 21, 22, or 23 in ubuntu 26.04 | 24.04 | 22.04
Install Clang 21, 22, or 23 in Ubuntu 26.04 | 24.04 | 22.04 | UbuntuHandbook
... It’s usually installed to ... to verify. If you do need to make it clang, use update-alternatives command to make all installed clang versions as alternatives to /usr/bin/clang, and set your desired version as default....
🌐
Digipen
azrael.digipen.edu › ~mmead › www › mg › update-compilers › index.html
Mead's Guide to Upgrading GCC and Clang on Linux
November 16, 2021 - To setup the two versions of Clang: sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.5 50 --slave /usr/bin/clang++ clang++ /usr/bin/clang++-3.5 sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.8 60 --slave /usr/bin/clang++ clang++ /usr/bin/clang++-3.8 ...
🌐
GitHub
github.com › toprakkeskin › clang-8-update-alternatives-script
GitHub - toprakkeskin/clang-8-update-alternatives-script: Inserts update-alternative entries for all the binaries related clang-8 and llvm and makes clang default c and c++ compiler.
Inserts update-alternative entries for all the binaries related clang-8 and llvm and makes clang default c and c++ compiler. Add the sources (for ubuntu): deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-8 main deb-src http://apt.llvm....
Starred by 8 users
Forked by 6 users
Languages   Shell 100.0% | Shell 100.0%
Find elsewhere
🌐
Mousepawmedia
devdocs.mousepawmedia.com › tools › cpp.html
C++ and C Development Environment — MousePaw Media Development Docs 1.0.0 documentation
If you use any drivers that require recompiling when you update the kernel, you will need to switch back to GCC before running updates! sudo update-alternatives --config cc and sudo update-alternatives --config c++. Just be sure to switch to Clang before you start working with your code again.
🌐
Kkweon
kkweon.dev › posts › how-to-correctly-manage-different-versions-in-ubuntu
How to correctly manage different versions in Ubuntu
March 13, 2018 - You can see that my clang is pointing clang-7.0. So, you just have to create a symbolic link inside alternatives directory, and you will always use the right version. Ubuntu also comes with update-alternatives which is a helper utility to manage alternatives symlinks.
🌐
WIIIN0DE
blog.wellosoft.net › update-llvm-from-18-to-21-in-ubuntu-24
Update LLVM from 18 to 21 In Ubuntu 24 - WIIIN0DE
September 3, 2025 - Here’s I do it, first install the llvm 21: wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh sudo ./llvm.sh 21 Then install all LLVM tools sudo apt install llvm-21* clang-21* lld-21* lldb-21* Then install the alternatives (see the script) wget htt...
🌐
Stack Exchange
unix.stackexchange.com › questions › 596226 › how-to-change-clang-10-llvm-10-etc-to-clang-llvm-etc
compiling - How to change clang-10, llvm-10, etc to clang, llvm, etc.? - Unix & Linux Stack Exchange
July 2, 2020 - Then, changed clangd-10 to clangd using the following command: $ sudo update-alternatives --install /usr/bin/clangd clangd /usr/bin/clangd-10 100 · Now, how can I change the other packages like clang-10, llvm-10, lldb-10, lld-10 etc. to clang, ...
🌐
GitHub
gist.github.com › junkdog › 70231d6953592cd6f27def59fe19e50d
update-alternatives-clang.sh · GitHub
#!/usr/bin/env bash # --slave /usr/bin/$1 $1 /usr/bin/$1-\${version} \\ function register_clang_version { local version=$1 local priority=$2 update-alternatives \ --verbose \ --install /usr/bin/llvm-config llvm-config /usr/bin/llvm-config-${version} ${priority} \ --slave /usr/bin/llvm-ar llvm-ar /usr/bin/llvm-ar-${version} \ --slave /usr/bin/llvm-as llvm-as /usr/bin/llvm-as-${version} \ --slave /usr/bin/llvm-bcanalyzer llvm-bcanalyzer /usr/bin/llvm-bcanalyzer-${version} \ --slave /usr/bin/llvm-c-test llvm-c-test /usr/bin/llvm-c-test-${version} \ --slave /usr/bin/llvm-cat llvm-cat /usr/bin/llvm
🌐
GitHub
gist.github.com › bhaskarvk › 78a80d9b5d308c84ba43b4a4e599a439
Proper GCC (vers. 5/6/7) & LLVM/CLANG (vers. 4/5) Toolchain Setup on Ubuntu/Linux Mint · GitHub
This script can be used to change systemwide default compiler/linker combination to either GCC or CLANG. Once these scripts are run you can change the system GCC/CLANG versions by running sudo update-alternatives --config gcc|clang.
🌐
The Fedora Project
fedoraproject.org › wiki › Changes › Use-Update-Alternatives-For-usr-bin-cc
Changes/Use-Update-Alternatives-For-usr-bin-cc - Fedora Project Wiki
February 11, 2021 - For this change, the gcc package will be modified so that update-alternatives creates and manages these symlinks. In addition to modifying the gcc package, the clang package will be modified so that /usr/bin/clang and /usr/bin/clang++ can be used as alternatives for /usr/bin/cc and /usr/bin/c++. The clang alternatives will have a lower priority than the gcc alternatives, so that by default, gcc will provide the /usr/bin/cc and /usr/bin/c++ implementations.
🌐
Linux Questions
linuxquestions.org › questions › linux-software-2 › ubuntu-18-04-how-to-set-clang-as-default-compiler-using-update-alternatives-4175652608-print
LinuxQuestions.org - Ubuntu 18.04 - how to set clang as default compiler using update-alternatives
April 23, 2019 - - - Ubuntu 18.04 - how to set clang as default compiler using update-alternatives (https://www.linuxquestions.org/questions/linux-software-2/ubuntu-18-04-how-to-set-clang-as-default-compiler-using-update-alternatives-4175652608/)
🌐
Eosio
eosio.github.io › history-tools › build-ubuntu-1804.html
Ubuntu 18.04 · GitBook
apt update && apt install -y wget gnupg cd ~ wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - apt update && apt install -y \ autoconf2.13 \ build-essential \ bzip2 \ cargo \ clang-8 \ git \ libgmp-dev \ libpq-dev \ lld-8 \ lldb-8 \ ninja-build \ nodejs \ npm \ pkg-config \ postgresql-server-dev-all \ python2.7-dev \ python3-dev \ rustc \ zlib1g-dev update-alternatives --install /usr/bin/clang clang /usr/bin/clang-8 100 update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-8 100
🌐
Linux Mint Forums
forums.linuxmint.com › board index › main edition support › software & applications
Update clang-format to version 10.0.0? - Linux Mint Forums
July 10, 2020 - I then followed an example for clang found here: https://askubuntu.com/questions/791616/ ... as-default Here are the cmd's I entered (which I modified to suit my needs): ... sudo update-alternatives --install /usr/bin/clang-format-6.0 clang-format-6.0 /usr/bin/clang-format-10 100 sudo ...