How to install Clang 11 on Debian

11,841

I found the solution after some searching. Here is what I did to make it work:

  1. Add the following lines to your /etc/apt/sources.list:
deb http://apt.llvm.org/buster/ llvm-toolchain-buster main 
deb-src http://apt.llvm.org/buster/ llvm-toolchain-buster main 
deb http://apt.llvm.org/buster/ llvm-toolchain-buster-10 main 
deb-src http://apt.llvm.org/buster/ llvm-toolchain-buster-10 main 
deb http://apt.llvm.org/buster/ llvm-toolchain-buster-11 main 
deb-src http://apt.llvm.org/buster/ llvm-toolchain-buster-11 main
  1. Add signatures for these repos (otherwise apt-get update will complain in the next step)
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
  1. Run apt-get update to add these new repos to the apt-get:
sudo apt-get update
  1. Install clang-11:
sudo apt-get install clang-11
  1. Make sure now "clang-11" is used by the compiler and not the older "clang":
export CMAKE_C_COMPILER=clang-11
export CMAKE_CXX_COMPILER=clang++-11
  1. Compile your project.
  2. Enjoy!

For documentation: https://apt.llvm.org/

Share:
11,841
Frida Schenker
Author by

Frida Schenker

Updated on June 04, 2022

Comments

  • Frida Schenker
    Frida Schenker almost 2 years

    I am trying to compile a C++ project on a PC with "Debian GNU/Linux 10". The project requires clang, so I installed it with:

    sudo apt-get install clang
    

    But I run into the following error:

    Clang version must be at least 11, the version used is 7.0.1
    

    How can I install clang 11?

    Note: I do not want to install the entire LLVM package again. Just want to upgrade Clang from version 7 to 11, preferably via command-line.