Skip to content
Latchkey

Ruby "Failed to build gem native extension" (missing gcc) in CI

A gem with a C extension needs a working compiler toolchain to install. On a minimal runner image where gcc/clang or make is absent, mkmf or make fails immediately and Bundler reports "Failed to build gem native extension".

What this error means

gem install or bundle install fails with "Failed to build gem native extension" and the log shows the compiler or make is not found (e.g. "no acceptable C compiler found" or "make: command not found").

bundler
Building native extensions. This could take a while...
ERROR: Failed to build gem native extension.

checking for cc... no
checking for gcc... no
*** No acceptable C compiler found in $PATH ***

Common causes

No C compiler on the runner

A slim base image omits gcc/clang. Native gems cannot compile without one.

make or other build tools are missing

Even with a compiler, the extension build needs make and supporting tools that the image does not include.

How to fix it

Install a build toolchain

Add the compiler and make before installing native gems.

Terminal
# Debian/Ubuntu
sudo apt-get update
sudo apt-get install -y build-essential
# Alpine
# apk add build-base
bundle install --jobs 4

Avoid compiling where you can

Prefer precompiled platform gems so no compiler is required at install time.

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

How to prevent it

  • Install build-essential (or build-base on Alpine) before native gem installs.
  • Use precompiled platform gems to avoid compiling on CI altogether.
  • Choose a runner image that already includes a C toolchain.

Related guides

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