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++ 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
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.
PATHwould have worked as well, I'm sure.