# Latest Bundler fails to be used even when explicitly installed

**URL:** <https://discuss.circleci.com/t/latest-bundler-fails-to-be-used-even-when-explicitly-installed/34387>\
**Category:** Bug Reports\
**Tags:** rails, ruby, rubygems, docker, bundler\
**Created:** [February 6, 2020, 12:55am UTC](https://discuss.circleci.com/t/latest-bundler-fails-to-be-used-even-when-explicitly-installed/34387 "2020-02-06T00:55:50Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![kyleboe](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/kyleboe/32/24132_2.png) [@kyleboe](https://discuss.circleci.com/u/kyleboe)\
**Post date:** [February 6, 2020, 12:55am UTC](https://discuss.circleci.com/t/latest-bundler-fails-to-be-used-even-when-explicitly-installed/34387/1 "2020-02-06T00:55:50Z")

</div>

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](https://discuss.circleci.com/t/using-bundler-2-0-during-ci-fails/27411):

```
version: 2
jobs:
  build:
    docker:
      - image: circleci/ruby:2.6.5
    steps:
      - 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).

---

<div class="post-metadata">

**Author:** ![kyleboe](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/kyleboe/32/24132_2.png) [@kyleboe](https://discuss.circleci.com/u/kyleboe)\
**Post date:** [February 6, 2020, 6:43pm UTC](https://discuss.circleci.com/t/latest-bundler-fails-to-be-used-even-when-explicitly-installed/34387/2 "2020-02-06T18:43:37Z")

</div>

Finally found a solution. 😑 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.

---

<div class="post-metadata">

**Author:** ![kyleboe](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/kyleboe/32/24132_2.png) [@kyleboe](https://discuss.circleci.com/u/kyleboe)\
**Post date:** [February 10, 2020, 6:05pm UTC](https://discuss.circleci.com/t/latest-bundler-fails-to-be-used-even-when-explicitly-installed/34387/3 "2020-02-10T18:05:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bytesguy](https://avatars.discourse-cdn.com/v4/letter/b/0ea827/32.png) [@bytesguy](https://discuss.circleci.com/u/bytesguy)\
**Post date:** [February 11, 2020, 3:25pm UTC](https://discuss.circleci.com/t/latest-bundler-fails-to-be-used-even-when-explicitly-installed/34387/4 "2020-02-11T15:25:02Z")

</div>

Hi Kyle,

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

 ![Screenshot 2020-02-11 at 15.20.21](https://global.discourse-cdn.com/circleci/original/3X/4/f/4f4318c3637fcb25c969a53e69eb061d0606d0ff.png)

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!

---

<div class="post-metadata">

**Author:** ![kyleboe](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/kyleboe/32/24132_2.png) [@kyleboe](https://discuss.circleci.com/u/kyleboe)\
**Post date:** [February 11, 2020, 4:45pm UTC](https://discuss.circleci.com/t/latest-bundler-fails-to-be-used-even-when-explicitly-installed/34387/5 "2020-02-11T16:45:35Z")

</div>

Thanks for reaching out!

The repo is open source: [https://github.com/hintmedia/moderate\_parameters](https://github.com/hintmedia/moderate_parameters)

I think this run best encapsulates my confusion with all of this: [https://circleci.com/gh/hintmedia/moderate\_parameters/88](https://circleci.com/gh/hintmedia/moderate_parameters/88)

---

<div class="post-metadata">

**Author:** ![FelicianoTech](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/felicianotech/32/21348_2.png) [@FelicianoTech](https://discuss.circleci.com/u/FelicianoTech)\
**Post date:** [February 13, 2020, 3:36pm UTC](https://discuss.circleci.com/t/latest-bundler-fails-to-be-used-even-when-explicitly-installed/34387/6 "2020-02-13T15:36:29Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![kyleboe](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/kyleboe/32/24132_2.png) [@kyleboe](https://discuss.circleci.com/u/kyleboe)\
**Post date:** [February 13, 2020, 11:02pm UTC](https://discuss.circleci.com/t/latest-bundler-fails-to-be-used-even-when-explicitly-installed/34387/7 "2020-02-13T23:02:57Z")

</div>

I removed everything else and it blows up like before: [https://circleci.com/gh/hintmedia/moderate\_parameters/145](https://circleci.com/gh/hintmedia/moderate_parameters/145)

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.

---

<div class="post-metadata">

**Author:** ![kyleboe](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/kyleboe/32/24132_2.png) [@kyleboe](https://discuss.circleci.com/u/kyleboe)\
**Post date:** [February 13, 2020, 11:20pm UTC](https://discuss.circleci.com/t/latest-bundler-fails-to-be-used-even-when-explicitly-installed/34387/8 "2020-02-13T23:20:24Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![kyleboe](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/kyleboe/32/24132_2.png) [@kyleboe](https://discuss.circleci.com/u/kyleboe)\
**Post date:** [February 13, 2020, 11:55pm UTC](https://discuss.circleci.com/t/latest-bundler-fails-to-be-used-even-when-explicitly-installed/34387/9 "2020-02-13T23:55:33Z")

</div>

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](https://github.com/rubygems/rubygems/compare/v3.0.6...v3.1.0), there is a fair bit of delta in `lib/rubygems.rb` surrounding how bundler gets loaded.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [February 23, 2020, 11:55pm UTC](https://discuss.circleci.com/t/latest-bundler-fails-to-be-used-even-when-explicitly-installed/34387/10 "2020-02-23T23:55:34Z")

</div>

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