17

I've joined a project which is using bundler version 1.17.1 . Currently my system is using bundler 2.0.2 . Is there any way for me to specify a bundler version just like specifying ruby version with rbenv. Something likes:

bundler --global 1.17.1

So that, when I run the command bundler -v I will receive the result 1.71.1 rather than 2.0.2

I tried to uninstall the current bundler with gem uninstall bundler and received this message:

$ gem uninstall bundler

Select gem to uninstall:
 1. bundler-1.17.1
 2. bundler-1.17.3
 3. bundler-2.0.2
 4. All versions
> 

That makes me think there is a certain way allows me to work with multiple bundler versions. Any clues just for pointing me to where I should look up would be really appreciated.

EDIT 1

I tried bundle _1.17.1_ --version and it didn't work as I expected

$ bundler -v
Bundler version 2.0.2
$ bundle _1.17.1_ --version
Bundler version 1.17.1
$ bundler -v
Bundler version 2.0.2

expected: Bundler version 1.17.1

actual: Bundler version 2.0.2

You Nguyen
  • 9,961
  • 4
  • 26
  • 52

2 Answers2

27

Try this:

1) gem install bundler -v 1.17.1

2) bundle _1.17.1_ install

Miro
  • 374
  • 3
  • 10
6

You can specify multiple bundler versions by using underscores: RubyGems already provides this functionality. Specify the version number in underscores as the first argument on the command line.

$ bundle _1.1.3_ --version
Bundler version 1.1.3
$ bundle _1.1.0_ --version
Bundler version 1.1.0
$ bundle _1.0.22_ --version
Bundler version 1.0.22

There's an issue in rbenv with a similar question: https://github.com/rbenv/rbenv/issues/235.

Hope this helps

Waclock
  • 1,686
  • 19
  • 37
  • 2
    This doesn't change the default. You need to add the version `_1.17.1_` every time you run the `bundle` command. Or if you want `bundle` command to point to this version every time, you can alias it in your rc file like `alias bundle='bundle _1.17.1_'`. – hchhabra Jul 04 '19 at 06:30
  • ```bundle _1.3.0_ install``` returns ```Could not find command "_1.3.0_".``` – David Geismar May 19 '20 at 18:18