Skip to content
Latchkey

Ruby Gem Build "clang/gcc: command not found" in CI

A gem tried to compile a native extension but there is no working C compiler on the runner. The gcc or clang binary is missing, so the build cannot even start.

What this error means

A native gem build fails immediately with "gcc: command not found" or "clang: command not found", or mkmf reports "The compiler failed to generate an executable file". The compiler itself is absent - distinct from a header-not-found error where the compiler runs but cannot find a file.

build output
make: gcc: No such file or directory
make: *** [Makefile:245: extension.o] Error 127

# or from mkmf
The compiler failed to generate an executable file.
You have to install development tools first.

Common causes

No C toolchain on a slim image

Slim and Alpine base images omit a compiler to stay small. Any gem without a precompiled build then fails because gcc/clang is not installed.

Toolchain present but incomplete

make and headers may exist while the actual compiler or its cc symlink is missing, so the build still cannot invoke the compiler.

How to fix it

Install the build toolchain

Terminal
# Debian/Ubuntu
apt-get update && apt-get install -y build-essential
# Alpine
apk add --no-cache build-base
# RHEL/Fedora
dnf groupinstall -y "Development Tools"

Avoid the compile with a precompiled gem

If the gem publishes a platform build, lock the Linux platform so no compiler is needed.

Terminal
bundle lock --add-platform x86_64-linux
bundle install

How to prevent it

  • Bake build-essential / build-base into images that compile gems.
  • Prefer precompiled platform gems in CI.
  • Use full base images (not slim/Alpine) when native builds are unavoidable.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →