
If you do C or C++ development on Linux, having the right compiler on your system is not optional. Clang, the C/C++ front-end for the LLVM compiler infrastructure, is one of the best tools you can add to a Fedora workstation or server. Fedora 43 ships with Clang 21 as part of its system-wide LLVM 21 update, which means the packages are already in the default DNF repositories and ready to install in minutes.
This guide walks you through every step to install Clang on Fedora 43: from updating your system and installing the right packages, to compiling real C and C++ programs, using the static analyzer, and fixing the most common errors you will run into. By the end, you will have a fully working Clang setup on Fedora 43 that you can use for personal projects, professional development, or CI pipeline work.
What Is Clang and Why Use It on Fedora 43?
Clang is an open-source compiler front-end for C, C++, Objective-C, and Objective-C++. It runs on top of the LLVM compiler infrastructure, which handles the back-end code generation and optimization. Originally developed at Apple, Clang is now maintained by a large open-source community and is used in production environments across Linux, macOS, FreeBSD, and Android.
Fedora ships GCC by default, and GCC is a solid compiler. But Clang brings a different set of advantages that make it worth adding to your toolbox.
Here is why many developers prefer Clang alongside GCC:
- Better error messages. Clang points directly to the line and character where the problem is. GCC messages can be harder to parse, especially for template errors in C++.
- Built-in static analysis. The
scan-buildtool and Clang static analyzer catch null pointer dereferences, memory leaks, and use-after-free bugs at compile time. - Sanitizers. AddressSanitizer, ThreadSanitizer, and UndefinedBehaviorSanitizer are first-class features in Clang.
- LSP support.
clangd, which ships in theclang-tools-extrapackage, gives you a language server for real-time code completion and error checking in VS Code, Neovim, and Emacs. - GCC-compatible flags. You can swap
gccforclangin most Makefiles without changing a single flag.
Clang vs GCC: Quick Comparison
| Feature | Clang 21 | GCC 14 |
|---|---|---|
| Default on Fedora 43 | No (installable) | Yes |
| Error message clarity | Excellent | Good |
| Built-in static analyzer | Yes (scan-build) |
Limited |
| Sanitizer support | Full (ASan, TSan, UBSan) | Partial |
| LSP server | clangd |
ccls (third-party) |
| C++20 / C++23 support | Yes | Yes |
| Kernel compilation support | Yes (LLVM=1) |
Yes |
What Changed in Clang 21 on Fedora 43
Fedora 43 adopts LLVM 21 as the system-wide LLVM version, targeting all sub-projects including Clang, Flang, MLIR, Polly, and libclc.
The two most important changes for everyday users are:
- Profile-Guided Optimization (PGO). The LLVM package is now built with PGO. This means Clang itself compiles your C and C++ files noticeably faster than it did in Fedora 42 with Clang 20.
- LLVM 20 compatibility package. A
llvm20-libscompat package is available to ensure that existing packages which depend on LLVM 20 libraries continue to work without breaking after the upgrade.
Prerequisites
Before you start, confirm the following:
- Operating system: Fedora 43 (fresh install or upgraded from Fedora 42)
- User permissions: A non-root user with
sudoaccess - Internet connection: Required for DNF to pull packages from the Fedora repositories
- System state: Your system packages should be up to date before adding new compilers
- Disk space: At least 500 MB free for Clang, LLVM, and related libraries
To check which version of Fedora you are running, open a terminal and type:
cat /etc/fedora-release
Expected output:
Fedora release 43 (Forty Three)
If you see Fedora 42 or earlier, the commands in this guide will still work but the package versions will differ.
Step 1: Update Your System Before Installing Clang
Keeping your system updated before installing a new package prevents dependency conflicts and ensures you get the latest package metadata from Fedora’s repositories.
Run the following command:
sudo dnf update -y
What this does: dnf update downloads and installs all pending package updates. The -y flag automatically answers “yes” to all confirmation prompts so the process runs without interruption.
Why this matters: Fedora 43 uses DNF5 as the default package manager. If your system has stale metadata from a partial upgrade or a previous session, running dnf update first syncs everything and prevents “nothing provides” errors during Clang installation.
After the update completes, reboot if the kernel was updated:
sudo reboot
Step 2: Install Clang on Fedora 43
With your system up to date, you can now install Clang on Fedora 43 directly from the official Fedora repositories using DNF.
Install the Core Clang Package
This single command installs the Clang compiler and its runtime libraries:
sudo dnf install clang -y
What this installs: The clang package pulls in clang-libs and compiler-rt as automatic dependencies. You get the clang and clang++ binaries in /usr/bin/.
Expected output (abbreviated):
Dependencies resolved.
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
clang x86_64 21.1.8-4.fc43 updates 28 M
Installing dependencies:
clang-libs x86_64 21.1.8-4.fc43 updates 143 M
compiler-rt x86_64 21.1.8-4.fc43 updates 57 M
Transaction Summary
================================================================================
Install 3 Packages
Total download size: 228 M
Installed size: 780 M
Is this ok [y/N]: y
Install Clang Together with LLVM Tools
If you plan to use LLVM tools such as llvm-config, opt, or llc alongside Clang, install both in the same command:
sudo dnf install clang llvm -y
What this adds: The llvm package gives you the full LLVM toolchain utilities. These are useful when building projects that use CMake with LLVM as a dependency or when you need llvm-config to query compiler flags.
Install Clang Tools Extra
The clang-tools-extra package is separate from clang on Fedora 43 and contains the tools most developers actually use day to day.
sudo dnf install clang-tools-extra -y
What this installs:
clangd– The Clang language server (LSP) for editor integrationclang-tidy– A C++ linter with 400+ checksclang-format– An auto-formatter for C, C++, Java, JavaScript, and moreclang-apply-replacements– Applies fixes suggested by clang-tidy in bulk
Note: Since Fedora 32, clang-format lives in clang-tools-extra, not in the base clang package. If you run clang-format and get “command not found” after installing only clang, this is exactly why.
Install Clang Development Headers (For Plugin and Tool Authors)
If you are writing tools that use Clang as a library, you need the development headers:
sudo dnf install clang-devel clang-tools-extra-devel -y
These packages install the C++ header files needed to compile programs against Clang’s API. You do not need these for regular C or C++ development.
Step 3: Verify the Clang Installation
After installation, confirm that Clang is working correctly before writing any code.
Check the Clang Version
clang --version
Expected output on Fedora 43:
clang version 21.1.8 (Fedora 21.1.8-4.fc43)
Target: x86_64-redhat-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Check the C++ Front-End
clang++ --version
You should see the same version number. Both clang and clang++ point to the same installed binary with different driver modes.
Confirm Binary Locations
which clang
which clang++
which clang-format
which clang-tidy
which clangd
All of these should return paths under /usr/bin/. If any return nothing, the corresponding package is not installed.
Inspect the Installed Package
dnf info clang
This shows the package version, repository source, install date, and size. It confirms you are running the Fedora 43 version and not a leftover binary from a previous release.
Step 4: Compile Your First C Program with Clang
Now that Clang is installed and verified, test it by compiling a real program.
Write a Hello World in C
Create the source file:
nano hello.c
Add the following code:
#include <stdio.h>
int main() {
printf("Hello from Clang on Fedora 43!\n");
return 0;
}
Save and exit with Ctrl+O, then Ctrl+X.
Compile and Run It
clang hello.c -o hello
./hello
Expected output:
Hello from Clang on Fedora 43!
What -o hello does: The -o flag tells Clang to name the output binary hello instead of the default a.out.
Compile with Optimization and Warnings
For real development builds, always enable warnings and optimization:
clang -Wall -Wextra -O2 hello.c -o hello
-Wallenables the most common warning categories-Wextraadds extra checks that-Walldoes not cover-O2applies standard optimizations for faster runtime performance
Clang’s output for this compile will be clean since the program has no issues. If you introduce a bug, Clang will tell you exactly which line and column the problem is on.
Step 5: Compile C++ Programs with Clang
C++ compilation works the same way, but you must use clang++ instead of clang.
Write a Hello World in C++
nano hello.cpp
#include <iostream>
int main() {
std::cout << "Hello from Clang++ on Fedora 43!" << std::endl;
return 0;
}
Compile with the C++17 Standard
clang++ -std=c++17 -Wall -O2 hello.cpp -o hello_cpp
./hello_cpp
Expected output:
Hello from Clang++ on Fedora 43!
Supported C++ standards in Clang 21:
| Flag | Standard |
|---|---|
-std=c++14 |
C++14 |
-std=c++17 |
C++17 |
-std=c++20 |
C++20 (full support) |
-std=c++23 |
C++23 (largely supported) |
Use -std=c++17 or -std=c++20 for new projects. C++20 is fully supported in Clang 21 and covers modules, concepts, coroutines, and ranges.
Step 6: Use the Clang Static Analyzer
The Clang Static Analyzer is one of the most underused features of Clang. It finds real bugs in your code without running it. You get this for free with the clang package.
Run the Analyzer with scan-build
Write a program with an intentional bug:
nano buggy.c
#include <stdlib.h>
int main() {
int *ptr = malloc(sizeof(int));
*ptr = 42;
return 0; // Memory leak: ptr never freed
}
Run the analyzer:
scan-build clang buggy.c -o buggy
Expected output:
scan-build: 1 bug found.
scan-build: Run 'scan-view /tmp/scan-build-XXXX' to examine bug reports.
Open the HTML report in a browser with scan-view or simply review the terminal output. The analyzer found the memory leak before you even ran the program.
Run clang-tidy on a File
clang-tidy hello.cpp -- -std=c++17
clang-tidy checks your code against a large set of rules covering performance, readability, and correctness. You can configure which checks to enable or disable using a .clang-tidy configuration file in your project root.
Step 7: Set Clang as the Default Compiler (Optional)
Fedora 43 keeps GCC as the system default. If you want to build projects using Clang without editing every Makefile, set the CC and CXX environment variables.
Set for the Current Session Only
export CC=/usr/bin/clang
export CXX=/usr/bin/clang++
This applies only to the current terminal session. Once you close it, GCC is the default again.
Make It Permanent
Add the export lines to your shell configuration file:
nano ~/.bashrc
Add at the bottom:
export CC=/usr/bin/clang
export CXX=/usr/bin/clang++
Apply the change:
source ~/.bashrc
Use Inline for a Single Build
For a safer approach that does not affect other projects, pass the compiler inline with make:
CC=clang CXX=clang++ make
This overrides the default for that one build without changing any system or user-level setting.
Manage Multiple Clang Versions with update-alternatives
Fedora 43 supports Clang 21 as the default and provides llvm20-libs for backward compatibility. If you need to switch between versions for testing, register them with update-alternatives:
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-21 100
sudo update-alternatives --config clang
The --config command presents an interactive menu to select the active version.
Troubleshooting Common Clang Issues on Fedora 43
Even on a clean Fedora 43 install, you may hit a few roadblocks. Here are the five most common ones and how to fix them.
Error 1: “clang: command not found”
Cause: The clang package is not installed or /usr/bin is not in your PATH.
Fix:
sudo dnf reinstall clang -y
ls -la /usr/bin/clang
If the binary is present but the command is not found, your PATH is missing /usr/bin. Add it:
export PATH=$PATH:/usr/bin
Error 2: “clang-format: command not found” After Installing clang
Cause: clang-format moved to the clang-tools-extra package on Fedora 32+. Installing only clang does not include it.
Fix:
sudo dnf install clang-tools-extra -y
Error 3: Missing clang-libs Dependency in Containers
When running Clang inside a Docker or Podman container on Fedora 43, you may see errors about missing clang-libs. This is a known packaging issue where the container image does not pull in clang-libs automatically.
Fix:
sudo dnf install clang-libs -y
Error 4: “cannot find crtbeginS.o” or Missing GCC Runtime
Cause: Clang uses GCC’s runtime libraries for linking on Linux. If GCC is not installed, linking will fail.
Fix: Install GCC and the C library development headers:
sudo dnf install gcc glibc-devel -y
Error 5: DNF Dependency Conflicts After Upgrading from Fedora 42
The soname change from LLVM 20 to LLVM 21 can cause dependency conflicts if old packages still expect LLVM 20 shared libraries.
Fix: Install the compatibility package and sync your system:
sudo dnf install llvm20-libs -y
sudo dnf distro-sync -y
This keeps LLVM 20 libraries available for old packages while your system runs LLVM 21 as the default.
Uninstalling Clang from Fedora 43
If you need to remove Clang from your system, use the following commands:
sudo dnf remove clang clang-tools-extra clang-devel -y
sudo dnf autoremove -y
What autoremove does: It removes any orphaned packages that were installed as dependencies of Clang but are no longer needed by any other package.
Before removing clang-libs, check if anything depends on it:
dnf repoquery --whatrequires clang-libs
If the output is empty, it is safe to remove. If other packages depend on it, leave it installed.
Congratulations! You have successfully installed Clang. Thanks for using this tutorial for installing the Clang on your Fedora 43 Linux system. For additional or useful information, we recommend you check the official Clang website.