apt - How to install clang-10 on Ubuntu 20.4 - Unix & Linux Stack Exchange
c++ - How to install Clang 11 on Debian - Stack Overflow
How to install clang in win, wsl or linux
Building Clang 18.1.5 on Linux with support for std modules
Videos
I'm new to clang. I am a GCC guy. I use Fedora. How should I install the latest version of clang and its dependencies on my system? What command should I run? Which packages should be installed in order to be able to build a basic C++ program which also has static linkage? Just run sudo dnf install clang? Anything else?
You are actually pretty close with the aptitude suggestion. If you look at what is installed, you see that the Ubuntu 18 versions of those packages are still present.
When I did sudo aptitude install clang, I got the same message as shown, but then typed 'n'. Aptitude then offers another solution, which is to offer to 'downgrade' to gcc 9. Allow it to do that, and let it return to the command prompt. Then then do sudo apt install clang and you'll get clang-10.
Personally I encountered this issue and solved it by installing LLVM using the Automatic installation script they mention in their apt packages page.
Installing the llvm and build-essential packages, as you have done, does not cause clang or clang++ to be installed. For that, you must install one of the clang packages, depending on which version of clang and clang++ you want.
16.04
In Ubuntu 16.04, your options are clang-3.5, clang-3.6, clang-3.7, and clang-3.8.
14.04
In Ubuntu 14.04, your options are clang-3.3 , clang-3.4
, and clang-3.5
.
You can install them in the Software Center, or with:
sudo apt-get update
sudo apt-get install clang-3.n
(Replacing n with the desired sub-version, of course.)
12.04
If you're running Ubuntu 12.04, there's only one package that provides clang and clang++, so it's just called clang .
18.04 (Bionic)
I visited http://apt.llvm.org/bionic/dists/ (i.e. bionic distributions).
I determined that 6.0 was the latest major version of the toolchain.
I assume that you'll want the linker, lld, also.
# grab the key that LLVM use to GPG-sign binary distributions
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-get update
sudo apt-add-repository "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-6.0 main"
sudo apt-get install -y clang-6.0 lld-6.0
This gives you binaries with the following names (and more, probably):
clang-6.0
clang++-6.0
lld-6.0
ld.lld-6.0
It also installs these packages (and more):
llvm-6.0
llvm-6.0-dev
llvm-6.0-runtime
17.04 (Artful)
Same as above. I'll repeat every line for convenient copy-paste.
# grab the key that LLVM use to GPG-sign binary distributions
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-get update
sudo apt-add-repository "deb http://apt.llvm.org/artful/ llvm-toolchain-artful-6.0 main"
sudo apt-get install -y clang-6.0 lld-6.0
16.04 (Xenial)
The accepted answer already gives instructions for installing clang-3.8 on 16.04, but here's how to get clang-6.0:
# grab the key that LLVM use to GPG-sign binary distributions
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-get update
sudo apt-add-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-6.0 main"
sudo apt-get install -y clang-6.0 lld-6.0
I found the solution after some searching. Here is what I did to make it work:
- Add the following lines to your /etc/apt/sources.list:
Copydeb 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
- Add signatures for these repos (otherwise apt-get update will complain in the next step)
Copywget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
- Run apt-get update to add these new repos to the apt-get:
Copysudo apt-get update
- Install clang-11:
Copysudo apt-get install clang-11
- Make sure now "clang-11" is used by the compiler and not the older "clang":
Copyexport CMAKE_C_COMPILER=clang-11
export CMAKE_CXX_COMPILER=clang++-11
- Compile your project.
- Enjoy!
For documentation: https://apt.llvm.org/
I would suggest installing the latest stable 15
- Add the following lines to your /etc/apt/sources.list:
Copydeb http://apt.llvm.org/bullseye/ llvm-toolchain-bullseye main
deb-src http://apt.llvm.org/bullseye/ llvm-toolchain-bullseye main
# 15
deb http://apt.llvm.org/bullseye/ llvm-toolchain-bullseye-15 main
deb-src http://apt.llvm.org/bullseye/ llvm-toolchain-bullseye-15 main
- Add signatures for these repos (otherwise apt-get update will complain in the next step)
Copywget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
- Run apt-get update to add these new repos to the apt-get:
Copy sudo apt update && sudo apt upgrade
- To install all key packages
Copysudo apt-get install libllvm-15-ocaml-dev libllvm15 llvm-15 llvm-15-dev llvm-15-doc llvm-15-examples llvm-15-runtime
- Install clang-15
Copy sudo apt-get install clang-15 lldb-15 lld-15
- Make sure now "clang-15" is used by the compiler and not the older "clang" and done just compile your project
Copyexport CMAKE_C_COMPILER=clang-15
export CMAKE_CXX_COMPILER=clang++-15
Doc https://apt.llvm.org/