How to install Clang 17 or 18 in Ubuntu 22.04 | 20.04
This simple tutorial shows how to install the latest Clang compiler 17 and/or 18 in Ubuntu 20.04, Ubuntu 22.04, and Ubuntu 23.10.
Ubuntu includes several versions of Clang in its system repositories. But, it rarely builds newer releases into Ubuntu stable repositories.
You can easily install Clang 10, 11, 12, 13, 14, and 15 by running sudo apt install clang-xx
(replace xx with major version number) command in terminal.
For the most recent 18 and 17, they are also easy to install via the official apt repository.
Step 1: Download the Automatic installation script
The official Clang repository, so far supports Ubuntu 18.04, Ubuntu 20.04, Ubuntu 22.04, Ubuntu 23.04, and Ubuntu 23.10. It has a script to make adding repository and installing Clang as easy as few Linux commands.
-
First, open terminal. When terminal opens, run command to download the official installation script:
wget https://apt.llvm.org/llvm.sh
You may also use the script in Debian stable, though you may need to install
wget
first. -
After downloading the script, add executable permission by running command:
chmod u+x llvm.sh
Step 2: Use the script to install Clang
The script automate the process of adding the official apt repository, updating package cache, and installing specific Clang version into your system.
All this can be done by running a single command. For example, install Clang-18:
sudo ./llvm.sh 18
Replace 18
with 17
for installing Clang-17, or even 19
if it’s already released when you see this tutorial
During the process, it will ask to hit Enter to confirm adding the apt repository. Then, you may just wait until the process done.
Step 3: Verify
If everything’s done successfully, just run clang-xx --version
and/or locate clang-xx
to verify.
Uninstall
To remove the repository added by the script, just open terminal (Ctrl+Alt+T) and run command to remove the corresponding source file:
sudo rm /etc/apt/sources.list.d/archive_uri-http_apt_llvm_org_*.list
And, remove the repository key file via command:
sudo rm /etc/apt/trusted.gpg.d/apt.llvm.org.asc
Or, launch “Software & Updates” and remove source line and key from “Other Software” and “Authentication” tabs.
To remove Clang packages (replace 18
accordingly), just run command:
sudo apt remove --autoremove clang-18 lldb-18 lld-18 clangd-18
标签:17,script,18,apt,Clang,install,Ubuntu
From: https://www.cnblogs.com/RioTian/p/17981544