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.)
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.8 100
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.8 100
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-8 81 --slave /usr/bin/clang++ clang++ /usr/bin/clang++-8 --slave /usr/share/man/man1/clang.1.gz clang.1.gz /usr/share/man/man1/clang-8.1.gz --slave /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-8 --slave /usr/bin/clang-format clang-format /usr/bin/clang-format-8
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-6.0 60 --slave /usr/bin/clang++ clang++ /usr/bin/clang++-6.0 --slave /usr/share/man/man1/clang.1.gz clang.1.gz /usr/share/man/man1/clang-6.0.1.gz --slave /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-6.0 --slave /usr/bin/clang-format clang-format /usr/bin/clang-format-6.0
These commands will add 2 entries and default selected as clang-8. You can configure using
sudo update-alternatives --config clang
This will update clang, clang++, man pages, clang-format, clang-tidy.
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
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.