Skip to content
Latchkey

Bundler "An error occurred while installing X, and Bundler cannot continue" in CI

Bundler installs gems one at a time; when one fails, it stops the whole run with "An error occurred while installing X, and Bundler cannot continue". The real cause (a native build error or a download failure) is in the output just above this line.

What this error means

bundle install fails with "An error occurred while installing gem-name (x.y.z), and Bundler cannot continue" and tells you to run gem install for that gem to see the full error.

Bundler
An error occurred while installing pg (1.5.6), and Bundler cannot continue.

In Gemfile:
  pg

Make sure that `gem install pg -v '1.5.6' --source 'https://rubygems.org/'`
succeeds before bundling.

Common causes

A native extension failed to compile

The gem builds a C extension that needs a system library or compiler the runner lacks, so the single-gem install fails.

The gem could not be fetched

A transient network error or a missing version on the source stopped the download for that one gem.

How to fix it

Reproduce the single-gem install

  1. Run the gem install command Bundler prints to see the real error.
  2. If it is a native build, install the missing -dev package first.
  3. Re-run bundle install once the underlying cause is fixed.
Terminal
gem install pg -v '1.5.6' --source 'https://rubygems.org/'

Install system libraries for native gems

For pg, nokogiri, mysql2 and similar, install the required headers before bundling.

Terminal
sudo apt-get update
sudo apt-get install -y build-essential libpq-dev

How to prevent it

  • Install the -dev packages native gems need before bundle install.
  • Prefer precompiled platform gems so no compilation runs in CI.
  • Cache the bundle so a transient fetch failure is not repeated.

Related guides

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