How to Install Clang on Ubuntu

Clang is available directly from Ubuntu's official repositories, so the simplest installation is to refresh APT and install the clang package. You do not need the old version-specific Clang 9, 11, or 12 instructions from earlier Ubuntu releases.

For most systems, run:

sudo apt update
sudo apt install clang

Then confirm the compiler with clang --version. The unversioned clang package follows the default Clang release selected by your Ubuntu version.

Which Clang version does Ubuntu install?

Ubuntu keeps a default clang metapackage in the Universe repository. The underlying compiler version differs by release. Ubuntu's official package index currently lists the following defaults:

Ubuntu releaseDefault compiler behind clang
22.04 LTSClang 14
24.04 LTSClang 18
26.04 LTSClang 21

You can verify these packages in the official Ubuntu package index. On your own computer, apt-cache policy clang shows the exact candidate APT will install.

Install Clang on Ubuntu with APT

1. Refresh the package list

Open Terminal and update APT's local package index:

sudo apt update
Ubuntu Terminal after running sudo apt update before installing Clang
Refresh Ubuntu's package list before installing Clang.

2. Install the Clang compiler

Install the default compiler package for your Ubuntu release:

sudo apt install clang

APT installs the compiler and its required dependencies. The old --install-suggests option is not necessary for a normal Clang installation.

Ubuntu Terminal showing sudo apt install clang
The clang package installs Ubuntu's default Clang compiler.

If APT reports that it cannot locate the package, make sure the Universe repository is enabled, then refresh the index again:

sudo add-apt-repository universe
sudo apt update
sudo apt install clang

On a minimal installation where add-apt-repository is missing, install software-properties-common first.

3. Verify Clang and Clang++

Check both the C and C++ compiler drivers:

clang --version
clang++ --version

The version number may differ from the example image because it depends on your Ubuntu release and enabled updates.

Ubuntu Terminal showing clang --version after installation
Use clang --version to confirm which compiler Ubuntu installed.

4. Compile a small C program

Create a file named hello.c with this code:

#include <stdio.h>

int main(void) {
    printf("Hello, Clang!\n");
    return 0;
}

Compile it and run the executable:

clang hello.c -o hello
./hello

You should see Hello, Clang!. The official Clang command guide explains additional compiler modes and options.

Ubuntu Text Editor and Terminal compiling hello.c with Clang and printing Hello, Clang
A successful test confirms that Clang can compile and link a simple C program.

Install a specific Clang version

If a project requires a particular toolchain, first see which versioned packages are available in your configured Ubuntu repositories:

apt-cache search '^clang-[0-9][0-9]*$'

Then install the version you need. For example, Ubuntu 24.04 LTS provides clang-18, while Ubuntu 26.04 LTS provides clang-21 as its default versioned compiler:

sudo apt install clang-18
# or, on a release that provides it:
sudo apt install clang-21

Use the matching executable such as clang-18 or clang-21 when you need to avoid ambiguity. Build systems can also be pointed at a specific compiler with variables such as CC=clang-21 and CXX=clang++-21.

Need a newer LLVM/Clang release?

If Ubuntu's repositories do not provide the version your project requires, LLVM maintains an official Debian/Ubuntu repository at apt.llvm.org. Its installer script can add the appropriate upstream repository and install a chosen LLVM version. A safer workflow is to download and review the script before running it:

wget https://apt.llvm.org/llvm.sh
less llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh <version-number>

Packages from apt.llvm.org are upstream LLVM packages, not Ubuntu archive packages, so use them when you specifically need a newer toolchain rather than replacing Ubuntu's default without a reason.

Common installation problems

  • “Unable to locate package clang”: run sudo apt update, confirm Universe is enabled, and make sure the Ubuntu release is still supported.
  • The wrong Clang runs: check command -v clang and clang --version. If multiple versions are installed, call the versioned binary directly.
  • A C++ build fails: use clang++ for C++ linking, because it automatically handles the C++ standard library setup expected by typical projects.
  • A project needs more build tools: Clang is only the compiler. Projects may separately require packages such as build-essential, cmake, or ninja-build.

Leave a Comment

How to Record Speaker Output on Linux with Audacity

How to Record Speaker Output on Linux with Audacity

Capture Linux desktop audio in Audacity by routing its recording stream to your output device’s monitor source. Follow PulseAudio and PipeWire steps, export tips, and fixes for silent tracks.

How to Use Dropbox on Linux: Install and Sync Your Files

How to Use Dropbox on Linux: Install and Sync Your Files

Install Dropbox on Linux from the official package, sign in, sync a local folder, manage selective sync, and check status from the command line.

How to Install Inkscape on Linux: Ubuntu, Fedora, Arch, and More

How to Install Inkscape on Linux: Ubuntu, Fedora, Arch, and More

Install Inkscape from your Linux distribution’s repositories, the Ubuntu stable PPA, Snap, or Flathub, with current commands and notes for choosing a package source.

How to Find and Remove Duplicate Files on Linux With FSlint

How to Find and Remove Duplicate Files on Linux With FSlint

Use FSlint to scan selected Linux folders, review duplicate groups, and safely delete redundant files or learn when hard-link merging is appropriate.

How to Install SABnzbd on Linux and Configure It

How to Install SABnzbd on Linux and Configure It

Install SABnzbd on Ubuntu or Debian, or run it in Docker on another Linux host. Then open the web interface and configure your provider and download folders.

How to Install the Paper GTK Theme on Linux

How to Install the Paper GTK Theme on Linux

Install the Paper GTK theme from supported Linux repositories, enable it for GTK apps in GNOME Tweaks, and see what the legacy theme can and cannot change.

How to Install and Set Up Plex on OpenMediaVault with Compose

How to Install and Set Up Plex on OpenMediaVault with Compose

The old OpenMediaVault Plex plugin is archived. Set up Plex on OMV 8 with OMV-Extras, the Compose plugin, persistent storage, and Plex’s official container.

How to Clean and Speed Up Ubuntu Safely

How to Clean and Speed Up Ubuntu Safely

Clean and speed up Ubuntu with safe APT cleanup, storage checks, and startup controls that help free space and troubleshoot a sluggish desktop.

How to Install the Hiri Email Client on Linux

How to Install the Hiri Email Client on Linux

Install Hiri on Linux with its Snap package or official tarball, add a desktop launcher, and check supported accounts plus a warning about Hiri’s old Snap release.

How to Get System Specifications for a Linux PC

How to Get System Specifications for a Linux PC

Use Fastfetch and built-in Linux commands to check your distro, kernel, CPU, memory, graphics, storage, and connected devices, then save a clear report.