How to install Clang 17 or 16 in Ubuntu 22.04 | 20.04

Last updated: September 26, 2023 — 5 Comments

This simple tutorial shows how to install the latest Clang compiler 17 and/or 16 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 16 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.

1. First, press Ctrl+Alt+T on keyboard to open terminal. When terminal opens, run command to download the official installation script:


You may also use the script in Debian stable, though you may need to install wget first.

2. After downloading the script, add executable permission by running command:

chmod u+x

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-17:

sudo ./ 17

Replace 17 with 16 for installing Clang-16, or even 18 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.


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/

Or, launch “Software & Updates” and remove source line and key from “Other Software” and “Authentication” tabs.

To remove Clang packages (replace 17 accordingly), just run command:

sudo apt remove --autoremove clang-17 lldb-17 lld-17 clangd-17


I'm a freelance blogger who started using Ubuntu in 2007 and wishes to share my experiences and some useful tips with Ubuntu beginners and lovers. Please comment to let me know if the tutorial is outdated! And, notify me if you find any typo/grammar/language mistakes. English is not my native language. Contact me via [email protected] Buy me a coffee:

5 responses to How to install Clang 17 or 16 in Ubuntu 22.04 | 20.04

  1. I dont see anything when typing clang –version, do we need to add something to the path variable after the script runs?

    • It’s usually installed to /usr/bin/clang-xx (e.g., clang-17, clang-16). So, you may run clang-17 --version to verify.

      If you do need to make it clang, use update-alternatives command to make all installed clang versions as alternatives to /usr/bin/clang, and set your desired version as default.

  2. I guess it doesn’t like Ubuntu 22.04.2 LTS??

    root@f767772ae40d:/# ./ 17
    + BASE_URL=
    + needed_binaries=(lsb_release wget add-apt-repository gpg)
    + missing_binaries=()
    + for binary in “${needed_binaries[@]}”
    + which lsb_release
    + for binary in “${needed_binaries[@]}”
    + which wget
    + for binary in “${needed_binaries[@]}”
    + which add-apt-repository
    + for binary in “${needed_binaries[@]}”
    + which gpg
    + [[ 0 -gt 0 ]]
    + ALL=0
    ++ lsb_release -is
    + DISTRO=Ubuntu
    ++ lsb_release -sr
    + VERSION=22.04
    + source /etc/os-release
    ++ PRETTY_NAME=’Ubuntu 22.04.2 LTS’
    ++ NAME=Ubuntu
    ++ VERSION_ID=22.04
    ++ VERSION=’22.04.2 LTS (Jammy Jellyfish)’
    ++ ID=ubuntu
    ++ ID_LIKE=debian
    ++ HOME_URL=
    ++ UBUNTU_CODENAME=jammy
    + DISTRO=ubuntu
    + case ${DISTRO} in
    + [[ -n jammy ]]
    + CODENAME=jammy
    + [[ -n jammy ]]
    + LINKNAME=-jammy
    + ‘[‘ 1 -ge 1 ‘]’
    + ‘[‘ 1 ‘!=’ – ‘]’
    + ‘[‘ 17 ‘!=’ all ‘]’
    + OPTIND=2
    + ‘[‘ 1 -ge 2 ‘]’
    + getopts :hm:n: arg
    + [[ 0 -ne 0 ]]
    + ‘[‘ ‘!’ _ ‘]’
    + [[ -n jammy ]]
    + REPO_NAME=’deb llvm-toolchain-jammy-17 main’
    + wget -q –method=HEAD
    + [[ -n ” ]]
    + echo ‘Distribution ‘\”ubuntu’\” in version ‘\”22.04.2 LTS (Jammy Jellyfish)’\” is not supported by this script.’
    Distribution ‘ubuntu’ in version ‘22.04.2 LTS (Jammy Jellyfish)’ is not supported by this script.
    + exit 2

    • Try updating your system!

      The latest packages were updated in December, which should be built against the latest Ubuntu 22.04.3 libraries.

      So, try if it works after updating from 22.04.2 to 22.04.3. To do so, simply launch “Software Updater” and install all available updates.

  3. How do I get llvm spirv 17 on my ubunut client with this script.

Leave a Reply

Text formatting is available via select HTML.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>