How to set Clang 3.9 as the default in Zesty?
Solution 1:
To build on the accepted answer, If you have multiple versions of clang, it may be in your best interest to make clang++
dependent on clang
so that all you need to do is update clang to a different version and the version of clang++ follows suit.
You can do this using the --slave
option of update-alternatives
. So something like this:
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.9 100 \
--slave /usr/bin/clang++ clang++ /usr/bin/clang++-3.9
You can of course do it for other versions:
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-4.0 100 \
--slave /usr/bin/clang++ clang++ /usr/bin/clang++-4.0
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-5.0 100 \
--slave /usr/bin/clang++ clang++ /usr/bin/clang++-5.0
To switch versions, you just type:
sudo update-alternatives --config clang
Enter a selection and both clang
and clang++
will be automatically switched to the same versions.
The same idea applies to GCC
if you also have multiple versions of that, you can use this method to configure gcc
and g++
.
Errors:
update-alternatives: error: alternative clang++ can't be slave of clang: it is a master alternative
You may get this error when you try to run the above commands. No worries, it just means that you already configured clang++
on it's own as an alternative, so you will need to remove that alternative before the above will work. You can do so with the command:
sudo update-alternatives --remove clang++ /usr/bin/clang++-3.9
Do this for each version of clang++, then after removing them all, try again.
Sources:
- https://codeyarns.com/2015/02/26/how-to-switch-gcc-version-using-update-alternatives/
- How to remove Oracle JDK
Solution 2:
This answer pointed me in the right direction:
sudo update-alternatives --install \
/usr/bin/clang++ clang++ /usr/lib/llvm-3.9/bin/clang++ 100
sudo update-alternatives --install \
/usr/bin/clang clang /usr/lib/llvm-3.9/bin/clang 100
After running those two commands, the build was able to continue.