Latest Bundler fails to be used even when explicitly installed

I am running into issues when attempting to use latest bundler (2.1.4) with docker. Even when checking bundler’s version I get errors:

#!/bin/bash -eo pipefail
bundle -v
Traceback (most recent call last):
  2: from /usr/local/bin/bundle:23:in `<main>'
  1: from /usr/local/lib/ruby/2.6.0/rubygems.rb:302:in `activate_bin_path'
/usr/local/lib/ruby/2.6.0/rubygems.rb:283:in `find_spec_for_exe': Could not find 'bundler' (2.1.4) required by your /home/circleci/project/Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:2.1.4`

This is even after I have stripped down my config.yml to almost nothing (bundler version script taken from here:

version: 2
      - image: circleci/ruby:2.6.5
      - checkout
      - run:
          name: Force Bundler Version
          command: |
            echo 'export BUNDLER_VERSION=$(cat Gemfile.lock | tail -1 | tr -d " ")' >> $BASH_ENV
            source $BASH_ENV
            gem install bundler
      - run:
          name: Do Anything Bundler Related
          command: bundler -v

Nothing seems to work and it looks like everything is installed correctly (ssh-ed onto the container and the bundler gem/corresponding version is definitely there).

1 Like

Finally found a solution. :expressionless: You have to force a system update of ruby gems by adding sudo gem update --system:

- run:
    name: Force Bundler Version
    command: |
      sudo gem update --system
      echo 'export BUNDLER_VERSION=$(cat Gemfile.lock | tail -1 | tr -d " ")' >> $BASH_ENV
      source $BASH_ENV
      gem install bundler

Hopefully the update to rubygems can be pushed to all ruby docker images used on circle.


Bump. Any word from the CircleCI team on this bug in ruby docker images?

Hi Kyle,

This is pretty strange as we have been unable to reproduce this issue using the circleci/ruby:2.6.5:

Can you reach out to us at support with some links to the failed jobs (unless this is for a public repo in which case feel free to post them here)? It seems like something is going wrong with the environment along the way in your jobs.


Thanks for reaching out!

The repo is open source:

I think this run best encapsulates my confusion with all of this:

Hey. As @bytesguy says, I can get this to work fine by just running gem install bundler which upgrades the pre-installed version.

Have you tried doing that without all of the other commands you ran?

I removed everything else and it blows up like before:

bundler installs but doesn’t seem to be recognized by the rest of the system.

The issue is no longer in the installation of bundler, but in running things via bundle exec.

I have also tried running the line from the appraisal gem on the machine:

circleci@eab1790625da:~/project$ BUNDLE_GEMFILE=/home/circleci/project/gemfiles/rails_5_2.gemfile bundle exec rspec --format progress --format RspecJunitFormatter --out /tmp/test-results/rspec.xml --format progress spec/moderate_parameters_spec.rb

Finished in 0.00439 seconds (files took 0.41847 seconds to load)
7 examples, 0 failures

I walked through rubygems versions (3.0.3 -> 3.0.4 -> 3.0.5 -> 3.0.6 -> 3.1.0) on the container and as soon as I upgraded to 3.1.0 the problem goes away.

Looking at the diff, there is a fair bit of delta in lib/rubygems.rb surrounding how bundler gets loaded.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.