Visit apt.llvm.org to verify the correct repository for your distribution.
Add a source-list file llvm-toolchain.sources to the directory /etc/apt/sources.list.d/.
cat <<EOD | sudo tee /etc/apt/sources.list.d/llvm-toolchain.sources >/dev/null
Types: deb
URIs: http://apt.llvm.org/$(lsb_release -sc)
Suites: llvm-toolchain-$(lsb_release -sc)
Components: main
Architectures: $(dpkg --print-architecture)
Signed-By:
$(wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sed 's/^/ /')
EOD
For older distributions not supporting .sources files.
The repository PGP key may already be installed on desktop distributions. If not, use the following commands to add the key and repository:
sudo wget https://apt.llvm.org/llvm-snapshot.gpg.key -O /etc/apt/trusted.gpg.d/apt.llvm.org.asc
echo "deb [arch=$(dpkg --print-architecture)] http://apt.llvm.org/$(lsb_release -sc)/ llvm-toolchain-$(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/llvm-toolchain.list
After adding the repository, update the package list and install the desired LLVM/Clang packages:
sudo apt update
sudo apt install clang lldb lld
You can install specific versions by appending the version number (e.g., clang-18, clang-19).
Since LLVM packages receive frequent updates, you can configure unattended upgrades for automatic updates.
Install the required package:
sudo apt install unattended-upgrades
Enable it using the following command:
sudo dpkg-reconfigure -plow unattended-upgrades
This modifies /etc/apt/apt.conf.d/20auto-upgrades, setting two flags:
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
Get repository information by running:
apt policy
The result will contain a section similar to:
500 http://apt.llvm.org/jammy llvm-toolchain-jammy/main amd64 Packages
release n=llvm-toolchain-jammy,c=main,b=amd64
origin apt.llvm.org
Create the file /etc/apt/apt.conf.d/51unattended-upgrades-llvm with the following content:
Unattended-Upgrade::Origins-Pattern {
"site=apt.llvm.org,component=main";
}