17

I have installed clang 3.0 and clang 3.8:

$ sudo update-alternatives --config clang

update-alternatives: error: no alternatives for clang.

How can I set 3.8 as /usr/bin/clang?

itnet7
  • 3,479
  • 2
  • 19
  • 20
Andrew
  • 649
  • 1
  • 5
  • 11
  • Make one or more clang entries to /etc/alternatives/ : `sudo update-alternatives --install "/usr/bin/clang" "clang" "[path-to]/clang" 1000` , like this java example http://askubuntu.com/questions/56104/how-can-i-install-sun-oracles-proprietary-java-jdk-6-7-8-or-jre – Knud Larsen Jun 26 '16 at 20:36
  • Actually, the name is 'cc'. So you need to issue: sudo update-alternatives --config cc – duli Dec 15 '18 at 16:23

3 Answers3

32
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
Videonauth
  • 33,045
  • 16
  • 104
  • 120
Andrew
  • 649
  • 1
  • 5
  • 11
  • I was following another example that used '60' to represent '6.0' and `--slave` instead of independent rules - what are your thoughts? `update-alternatives` doesn't look like it's doing much more than chaining symlinks, but I haven't used it enough to know what can go wrong. – John P Jun 04 '18 at 10:04
  • Thanks you for the answer. What does the `100` at the end mean? – banarun Feb 01 '19 at 12:53
  • The '100' is an arbitrary priority number; the application with the highest priority number will be used automatically unless you specify otherwise. For example, my system shows `gcc` with a priority of 20 and `clang` with a priority of 10; in auto mode, `update-alternatives` selects `gcc`. I could run the above with a priority of 50 and it would set the auto preference of `clang-3.8` above both existing options – arclight Aug 03 '19 at 16:22
5
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.

lxkarthi
  • 151
  • 1
  • 2
2

Try:

sudo update-alternatives --config cc

And it will present the list of options for you to choose.

make utility uses the command cc to compile, which is actually a link to gcc, clang etc.

duli
  • 479
  • 4
  • 5