Building musl libc on Fedora: From Source or Packages
Fedora’s default repositories don’t include musl libc, but you have two practical options: install it from a community repository if available, or build from source. Building from source gives you full control and is the most reliable approach across Fedora versions.
Option 1: Build from Source (Recommended)
Start by installing the build dependencies:
sudo dnf install gcc make
Download the latest musl libc source from the official site. Check musl-libc.org for the current stable version:
cd /tmp
wget https://musl.libc.org/releases/musl-1.2.5.tar.gz
tar xzf musl-1.2.5.tar.gz
cd musl-1.2.5
Configure and build:
./configure --prefix=/usr/local/musl
make
The --prefix option ensures musl installs to /usr/local/musl rather than system paths, keeping it isolated from glibc. Install it:
sudo make install
Add musl’s bin directory to your PATH permanently by editing ~/.bashrc:
export PATH="/usr/local/musl/bin:$PATH"
Then reload your shell:
source ~/.bashrc
Verify the installation:
musl-gcc --version
Using musl-gcc for Compilation
Once installed, you can compile C programs with musl instead of glibc:
musl-gcc -static -o myapp myapp.c
The -static flag bundles musl into the binary, creating a fully portable executable that doesn’t depend on the system libc.
For projects using autoconf, configure with:
CC=musl-gcc ./configure --prefix=/usr/local/musl-build
make
make install
Option 2: Check COPR Repositories
Some community maintainers provide musl packages via Fedora COPR. Search for available repositories:
dnf copr search musl
If a relevant repository exists, enable it:
sudo dnf copr enable <username>/musl
sudo dnf install musl musl-tools
This approach avoids compilation but depends on the repository being maintained for your Fedora version.
Common Issues
musl-gcc: command not found — Make sure /usr/local/musl/bin is in your PATH. Check with echo $PATH.
Compilation fails with missing headers — Ensure gcc and make are installed: sudo dnf install gcc make.
Static binaries still link glibc — Verify you’re using musl-gcc, not gcc. Run which musl-gcc to confirm the correct binary is in use.
Updating musl
To upgrade musl libc later, download a newer version, follow the same build steps, and reinstall. Your old version remains in /usr/local/musl until explicitly removed.
sudo rm -rf /usr/local/musl
Building musl from source gives you the flexibility to maintain multiple versions or customize the installation for specific projects.