Debian

How to Install the LLVM Clang C, C++, and Objective-C Compiler on Debian 12

Clang is a high-performance C, C++, and Objective-C compiler and toolset. Clang is an open-source project developed by the LLVM project. Clang-compiled programs are very fast and efficient. Clang also has amazing code optimization capabilities.  To make the identification of errors and fixing of code issues easier for developers, Clang provides better error messages and diagnostics. Clang is a good alternative to the GCC compiler and toolset.

In this article, we will show you how to install the LLVM Clang C, C++, and Objective-C compiler on Debian 12.

Topic of Contents:

  1. Updating the Debian 12 Package Database Cache
  2. Installing Clang C, C++, and Objective-C Compiler on Debian 12
  3. Checking If Clang C, C++, and Objective-C Compilers Are Accessible on Debian 12
  4. Installing Other Versions of Clang C/C++ Compiler on Debian 12
  5. Compiling the C and C++ Programs with LLVM Clang
  6. Conclusion

Updating the Debian 12 Package Database Cache

To update the Debian 12 package database cache, run the following command:

$ sudo apt update

 

Installing Clang C, C++, and Objective-C Compiler on Debian 12

To install the LLVM Clang C, C++, and Objective-C compiler and toolset on Debian 12, run the following command:

$ sudo apt install clang clangd clang-format clang-tidy clang-tools

 
To confirm the installation, press Y and then press <Enter>.


The LLVM Clang compilers and the required dependency packages are being downloaded from the internet. It takes a while to complete.


The LLVM Clang compilers and the required dependency packages are being installed. It takes a while to complete.


At this point, the LLVM Clang C, C++, and Object-C compiler should be installed on your Debian 12 system.

Checking If Clang C, C++, and Objective-C Compilers Are Accessible on Debian 12

To check whether you can access the Clang C, C++, and Objective-C compiler, run the following commands:

$ clang --version
$ clang++ --version

 
As you can see, Clang C, C++, and Objective-C compilers are accessible on our Debian 12 system. We have the Clang version 14 installed on our Debian 12 system.

Installing Other Versions of Clang C/C++ Compiler on Debian 12

On Debian 12, Clang 14 is installed by default as you’ve seen in the earlier section of this article. But Clang 13 and Clang 15 are available in the official package repository of Debian 12 as well.

To install Clang 13 on your Debian 12 system, run the following command:

$ sudo apt install clang-13 clangd-13 clang-format-13 clang-tidy-13 clang-tools-13

 
To install Clang 15 on your Debian 12 system, run the following command:

$ sudo apt install clang-15 clangd-15 clang-format-15 clang-tidy-15 clang-tools-15

 
To confirm the installation, press Y and then press <Enter>.


Your desired version of Clang and the required dependency packages are being downloaded. It takes a while to complete.


Your desired version of Clang is being installed. It takes a while to complete.


At this point, your desired version of Clang C, C++, and Objective-C compiler should be installed on your Debian 12 system.


If you installed Clang 15, you can check whether you can access Clang 15 C, C++, and Objective-C compiler with the following commands:

$ clang-15 --version
$ clang-15++

 

If you installed Clang 13, you can check whether you can access Clang 13 C, C++, and Objective-C compiler with the following commands:

$ clang-13 --version
$ clang-13++

 

Compiling the C and C++ Programs with LLVM Clang

If you need any assistance with compiling the C and C++ programs with LLVM Clang, read this article.

Conclusion

We showed you how to install the LLVM Clang C, C++, and Objective-C compiler on Debian 12 and how to install the Clang versions 13, 14, and 15 on Debian 12. We also showed you how to access Clang 13, 14, and 15 on Debian 12.

About the author

Shahriar Shovon

Freelancer & Linux System Administrator. Also loves Web API development with Node.js and JavaScript. I was born in Bangladesh. I am currently studying Electronics and Communication Engineering at Khulna University of Engineering & Technology (KUET), one of the demanding public engineering universities of Bangladesh.