Ruby bcrypt Gem Build Fails - Missing Compiler in CI
The bcrypt gem compiles a small self-contained C extension with no external library dependency. When it fails to build, the cause is almost always a missing C compiler or the Ruby headers - not a missing system library.
What this error means
bundle install fails building bcrypt’s native extension. Because bcrypt bundles its own C source, the error points at a missing compiler (gcc/clang) or missing Ruby headers rather than an absent -lXXX library.
Installing bcrypt 3.1.20 with native extensions
ERROR: Failed to build gem native extension.
make: gcc: No such file or directory
make: *** [Makefile:245: bcrypt_ext.o] Error 127Common causes
No C compiler on the runner
bcrypt needs gcc/clang to compile its bundled C source. A slim or Alpine image without a compiler fails the build immediately, since there is no precompiled gem to fall back to in many setups.
Ruby development headers missing
Even with a compiler present, the extension needs the Ruby headers (ruby-dev) to compile against the interpreter. Without them mkmf cannot configure the build.
How to fix it
Install the compiler and Ruby headers
# Debian/Ubuntu
apt-get update && apt-get install -y build-essential ruby-dev
# Alpine
apk add --no-cache build-base ruby-devConfirm the toolchain works
A quick check that gcc and the headers are present catches the problem before bundle install.
gcc --version
ruby -e 'puts RbConfig::CONFIG["rubyhdrdir"]'How to prevent it
- Bake build-essential and ruby-dev into images that build bcrypt.
- Use a full base image rather than slim when native gems are required.
- Cache vendor/bundle so the compile only happens when the gem changes.