Skip to content
Latchkey

Ruby grpc Gem Build Fails / Times Out in CI

The grpc gem ships a very large C/C++ extension. When no precompiled platform gem is used it compiles from source, which is slow and fails without a full toolchain - or times the job out entirely.

What this error means

bundle install spends many minutes "Building native extensions" for grpc and then fails (missing compiler/headers) or exceeds the step timeout. With the precompiled gem it should install in seconds.

bundler output
Installing grpc 1.62.0 with native extensions
Building native extensions. This could take a while...
ERROR: Failed to build gem native extension.
make: g++: command not found

Common causes

No precompiled grpc gem for the platform

When x86_64-linux is not locked (or force_ruby_platform is set), grpc compiles its large extension from source instead of using the prebuilt platform gem.

Missing C/C++ toolchain for the source build

The source build needs g++/gcc, make, and headers. On a slim image those are absent, so the compile fails - and even when present, it is slow enough to risk a timeout.

How to fix it

Use the precompiled platform gem

Lock the Linux platform so Bundler installs grpc’s prebuilt gem and skips the compile.

Terminal
bundle config set --local force_ruby_platform false
bundle lock --add-platform x86_64-linux
bundle install

If you must compile, install the toolchain

Terminal
# Debian/Ubuntu
apt-get update && apt-get install -y build-essential
# raise the step timeout so the long build can finish

How to prevent it

  • Lock x86_64-linux (and -musl on Alpine) so the precompiled grpc gem is used.
  • Keep force_ruby_platform off for grpc.
  • Bake build-essential into images that genuinely must compile grpc.

Related guides

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