Clang is a compiler for the C, C++, Objective-C, and Objective-C++ programming languages. It is part of the LLVM project, which provides a collection of modular and reusable compiler and toolchain technologies. This tutorial explains how to install Clang 19 on Ubuntu 24.04.
Install Clang
Download the LLVM GPG key:
sudo wget -qO /etc/apt/trusted.gpg.d/apt.llvm.org.asc https://apt.llvm.org/llvm-snapshot.gpg.key
Add the LLVM repository:
echo "deb http://apt.llvm.org/$(lsb_release -sc)/ llvm-toolchain-$(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/apt.llvm.org.list
Update the package lists:
sudo apt update
Install the Clang 19 and related tools:
sudo apt install -y clang-19
Verify the installation by checking Clang and Clang++ versions:
clang-19 --version
clang++-19 --version
Testing Clang
Create a main.c
file:
nano main.c
Add the following code into main.c
:
#include <stdio.h>
int main() {
printf("Hello world\n");
return 0;
}
Compile a code:
clang-19 main.c -o test
Run the program:
./test
Uninstall Clang
If you want to completely remove Clang and related dependencies, run the following command:
sudo apt purge --autoremove -y clang-19
Remove GPG key and repository:
sudo rm -rf /etc/apt/trusted.gpg.d/apt.llvm.org.asc
sudo rm -rf /etc/apt/sources.list.d/apt.llvm.org.list
Leave a Comment
Cancel reply