How to `bundle install` when your Gemfile requires an older version of bundler?
Asked Answered
T

6

117

I am in an older Rails project that has a Gemfile. I tried to add a gem to the Gemfile and bundle install but got an error:

Bundler could not find compatible versions for gem "bundler":
  In Gemfile:
    rails (= 3.0.0) ruby depends on
      bundler (~> 1.0.0) ruby

  Current Bundler version:
    bundler (1.1.5)

This Gemfile requires a different version of Bundler.

The version of Rails it's using requires bundler ~>1.0.0 but I have 1.1.5 installed and am using it for my other projects. Usually I would use bundle exec ... but since this is bundler we are talking about, it's a little more complicated than that. How can I add a gem to my Gemfile and run bundle install while using the version of bundler that it requires?

Tearoom answered 23/8, 2012 at 13:38 Comment(1)
I guess uninstall 1.1.5 bundler first. Then install 1.0.0. This will fix. Maybe there is a better solution?Uhf
T
219

First you need to install the appropriate version of bundler:

% gem install bundler -v '~> 1.0.0'
Successfully installed bundler-1.0.22

Then force rubygems to use the version you want (see this post):

% bundle _1.0.22_ install
Talkative answered 23/8, 2012 at 14:9 Comment(4)
Why the heck is this not in the Bundler docs?!? Thanks, after wasting more hours than I care to admit your answer finally explained what I needed.Ornithopod
To go for an exact version these days you will want to use gem install bundler -v '=1.16.0'Geier
Not working now. It cannot force rubygems to use the version which bundle _1.0.22_ install specifiedSelimah
I just used this approach and it worked for me @Selimah . I have both bundler 2.2.15 and bundler 2.2.16 installed.Steradian
S
11

This is what I had to do to get it to work to install with a previous version (2.2.11) of bundler:

gem install bundler:2.2.11
bundle _2.2.11_ install
Selfregulating answered 14/6, 2021 at 18:37 Comment(0)
L
4

The error message In Gemfile: bundler (~> 1.16) is a bit inaccurate, since the version number requirement can come from other places, such as the .gemspec file, which was the case for me:

spec.add_development_dependency "bundler", "~> 1.16"

Removing the version number from the .gemspec file solved the issue for me:

spec.add_development_dependency "bundler"
Lyophilize answered 18/9, 2019 at 9:19 Comment(0)
W
3

I had the same issue on macOS Mojave. I installed the different version of the bundler gem and uninstall the current version.

gem install bundler -i '2.0.1'

gem uninstall bundler

Then gives me the option to choose the version to uninstall and I choose the one which is creating the problem.

Wolfhound answered 4/9, 2019 at 18:13 Comment(1)
Not necessarily a recommended way of doing this. I'd try the accepted answer first, you might have other gems depending on the later versions, and you can run them separately.Bra
B
0

If you use rvm to manage your ruby versions consider using gemsets for projects. This way you can install the specific version of bundler needed without having to specify the version each time.

You can confirm your gemset is loaded by running rvm info in your project directory.

Now you can install the version of bundler you'd like via gem install bundler -v '~> <VERSION>'. The next time you need to use bundler just run bundle.

Bascom answered 21/2, 2023 at 18:51 Comment(0)
A
0

I was tasked to work on a legacy project requiring Ruby 2.x-something.

I was using rbenv, which gives a n00b like me no hints about how to resolve this issue.

Here's how I eventually got past the error:

$ grep bundler Gemfile.lock
      bundler (>= 1.3.0, < 2.0)
$ gem install bundler --version '>= 1.3.0, < 2.0'
Fetching: bundler-1.17.3.gem
...
$ bundle install

Inspecting the Gemfile.lock contents for the specific version of bundler was what helped me.

Ageratum answered 9/4 at 16:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.