43

I tried to change default bundle version but it getting updated with 2 default version. How can I modify to single default?

$ gem list bundler

*** LOCAL GEMS ***

bundler (2.0.1, default: 1.16.6, default: 1.16.2)

If I do gem uninstall not removing defaults,

$ gem uninstall bundler
Successfully uninstalled bundler-2.0.1


$ gem list bundle

*** LOCAL GEMS ***

bundler (default: 1.16.6, default: 1.16.2)

How can I set (like the below) default as single version?

bundler (2.0.1, default: 1.16.6)
Promise Preston
  • 24,334
  • 12
  • 145
  • 143
SST
  • 2,054
  • 5
  • 35
  • 65

10 Answers10

55

For those who use rbenv, let say by accidentally you have two default versions

$ gem list | grep bundler
bundler (default: 2.1.4, default: 1.17.2)

Check your gem installation path

$ gem environment
RubyGems Environment:
.
.
- INSTALLATION DIRECTORY: /home/yohanes/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0
.

Go to the specifications/default directory and look for bundlers gemspec

$ cd /home/yohanes/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/specifications/default
$ ls -lah
total 200K
drwxr-xr-x 2 yohanes yohanes 4,0K Jun  1 10:05 .
drwxr-xr-x 3 yohanes yohanes  20K Jun  1 10:05 ..
.
.
-rw-r--r-- 1 yohanes yohanes  16K Jun  1 10:05 bundler-1.17.2.gemspec
-rw-r--r-- 1 yohanes yohanes  15K Jun  1 09:31 bundler-2.1.4.gemspec
.
.

Remove the version that you need to remove

$ rm bundler-2.1.4.gemspec

Check again

$ gem list | grep bundler
bundler (default: 1.17.2)
$ gem list bundler

*** LOCAL GEMS ***

bundler (default: 1.17.2)

but, if you check bundle version, you still get the deleted version as default

$ bundler -v
Bundler version 2.1.4

So we have to overrides it by reinstalling the required bundler version again

$ gem install bundler --version '1.17.2'
Successfully installed bundler-1.17.2
Parsing documentation for bundler-1.17.2
Done installing documentation for bundler after 1 seconds
1 gem installed

Then, if you check again it will show you the desired version

$ bundle -v
Bundler version 1.17.2
yohanes
  • 2,365
  • 1
  • 15
  • 24
  • 3
    this is the best answer ever! – Anna Costalonga Aug 18 '20 at 15:23
  • 3
    Even after `gem install bundler` again, `bundle -v` still shows the wrong version. Any advice? – animatedgif Sep 24 '20 at 00:15
  • This just helped me – thefonso Apr 16 '21 at 03:26
  • mine still shows the version that I just removed. Then when i go to my xcode project and run bundle install - it gives me a warning about the lockfile version doesnt match – cspam May 04 '21 at 16:28
  • (1) If after all the above the old version is still there when you run `bundle -v`, try running `bundler _2.1.2_ install` with the explicit version, it fixed it for me. (2) This also works with ruby versions through `.asdf`. (3) I also still have the problem @cspam mentioned with the lockfile warning, not sure what's the "correct" way to resolve it... – Geekfish Aug 02 '21 at 15:55
  • 1
    In my case, `gem install bundler --version 'x.x.x'` worked as suggested, but after I still needed to do `gem install bundler:2.3.15` (even though it was already installed). Note that `gem install bundler -v 2.3.15` was not sufficient. – Miranda Short Aug 17 '22 at 15:16
  • 1
    I had been trying this command `gem install --default bundler:2.2.30`, it installed the gem and set it as default too but it did not change the bundler version returned by `bundler -v`, running `gem install bundler --version '2.2.30'` did work. Thanks a lot. – Masroor Dec 10 '22 at 02:50
39

I had the same problem but with a newer version

$ gem list bundler

*** LOCAL GEMS ***

bundler (default: 2.1.4, default: 2.1.2)

But after following indications on this post Two default versions of rake installed - how to delete one allowed me to deleted one.


You have to delete the .gemspec file corresponding to the default gem you want to delete.

So first, locate where those files are.

# I'm running RVM to manage my Ruby versions

~/.rvm/rubies/ruby-2.7.0/lib/ruby/gems/2.7.0/specifications/default/

-rw-r--r--   1 myuser  staff  10731 Dec 26 17:22 bundler-2.1.2.gemspec
-rw-r--r--   1 myuser  staff  15134 Jan  7 17:30 bundler-2.1.4.gemspec

Delete the one you don't need.

$ rm ~/.rvm/rubies/ruby-2.7.0/lib/ruby/gems/2.7.0/specifications/default/bundler-2.1.2.gemspec

Then install (or reinstall) the gem you want to set as default.

$ gem install bundler:2.1.4 --default

Successfully installed bundler-2.1.4 as a default gem

Finally you'll have installed only the version you wanted.

$ gem list bundler

*** LOCAL GEMS ***

bundler (default: 2.1.4)
Gabriel Cabrera
  • 509
  • 5
  • 6
  • 2
    Tried all that so many times, and gem list bundler and gem info bundler all say the correct version, but `bundler --version` prints old version, and bundle install still doesn't work. Pulling my hair out! – animatedgif Sep 23 '20 at 20:44
  • @animatedgif please run: bundler install – Feuda May 13 '21 at 04:16
  • @animatedgif if you have a BUNDLER_VERSION environment variable set, changing/removing that might help make the difference ... I had the same problem. Check with `env | grep -i bundle`; you can `unset BUNDLER_VERSION` if you need to – Aaron Wallentine Jun 06 '22 at 23:35
5

gem update --system

This command work for me

After run try this gem list bundler

Prateek Arora
  • 616
  • 8
  • 7
2

The rbenv path to the offending default .gemspec should be like below.

/Users/yourusername/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/specifications/default/bundler-2.1.2.gemspec
XJMZX
  • 21
  • 2
2

I observed that sometime default gems are not present in the INSTALLATION DIRECTORY path provided in the output of gem environment command.

I observed this problem in Alpine OS where Ruby v2.7.0 is installed.

In such cases you can use gem list -d <GEM_NAME> -v <VERSION> command to get the location where default gem is installed.

/ # gem list -d rexml -v 3.2.3

*** LOCAL GEMS ***

rexml (3.2.3)
    Author: Kouhei Sutou
    Homepage: https://github.com/ruby/rexml
    License: BSD-2-Clause
    Installed at (default): /usr/lib/ruby/gems/2.7.0

    An XML toolkit for Ruby

To remove default version you can use /usr/lib/ruby/gems/2.7.0 shown in above output. Delete command will be:

rm -rf <INSTALLED_AT_PATH>/specifications/default/<GEM_NAME>-<VERSION>.gemspec

For example:

rm -rf /usr/lib/ruby/gems/2.7.0/specifications/default/rexml-3.2.3.gemspec
pcsutar
  • 1,715
  • 2
  • 9
  • 14
2

With some bundler versions: you just get:

gem list bundler 
# bundler (2.1.4, default: 1.17.3)
  • you install new version of bundler, set it to default and you get multiple default bundler versions
gem install --default bundler -v2.3.8
# bundler (default: 2.3.8, 2.1.4, default: 1.17.3) 
  • and than you can reinstall old default version without --default parameter so it would be reinstalled as non-default and than you can uninstall it.
gem install bundler -v1.17.3
# bundler (default: 2.3.8, 2.1.4, 1.17.3)
  • and uninstall old default one
gem uninstall bundler -v1.17.3
# bundler (default: 2.3.8, 2.1.4)
lain0
  • 89
  • 3
  • 5
  • I get invald option --default for older rubygems versions – raquelhortab Jul 25 '22 at 12:49
  • than try ```gem update --system``` may be you have not a bug but lower system bundler gem version – lain0 Jul 25 '22 at 15:18
  • yup, I got an old version because I need an older version so updating is not a solution in my case – raquelhortab Jul 26 '22 at 07:48
  • This didn't work for me. I got `Gem bundler-2.1.4 cannot be uninstalled because it is a default gem Successfully uninstalled bundler-2.1.4` And then it re-appeared as a default gem. Using `rbenv`. – stwr667 Apr 15 '23 at 02:02
1

Came late to the party but perhaps my findings may help somebody:

After Ruby 2.6 bundler became a default gem this means that for each ruby version there's a default bundler, and the bundler gem comes with an executable bundle command.

You can't remove this gem and the only way to update the default gems is to update the RubyGems system using gem update --system [<version>]

I Had a lot of problems removing files in install paths to force the default gem, I wouldn't recommend but YMMV. In order to have a ruby 2.6.x with a 2.x default and working bundler, I had to start from a clean ruby installation and update the Rubygems to the point it had the bundler version that the project required.

theist
  • 3,270
  • 2
  • 22
  • 23
1

As @theist points out, after Ruby 2.6 bundler became a default gem. So depending on your version of Ruby, you will have a different version of bundler included. You can see the list here.

But what has not been explained in the answers so far is that you can control which version of bundler is used by editing your Gemfile.lock and specifying the version you want to use on the very last line of the file, where it says:

BUNDLED WITH
   2.2.33

This feels completely backwards since Gemfile.lock is supposed to be generated automatically by bundler, but that is the state of things at this point.

So, let's explain it all with an example. Let's say I am using Ruby 3.0.3. This version of Ruby comes with bundler 2.2.32. But my hosting company, Heroku, is using bundler 2.2.33. Since I want my dev environment to use the same bundler version as my production environment, I want to use 2.2.33.

So the first thing to do is gem install bundler -v "2.2.33". Then change the very bottom line of Gemfile.lock to say that it was bundled with 2.2.33 like:

BUNDLED WITH
   2.2.33

Now when you run bundle install it will use bundler 2.2.33.

Aaron Gray
  • 11,283
  • 7
  • 55
  • 61
0

You can find the default one at /usr/local/bin/, so if you delete that one and have ruby installed with homebrew for instance, it will dafault to the one that homebrew has.

After deleting it you should see something like:

enter image description here

open . /usr/local/bin/

bundler -v

Bundler version 2.3.25

which bundler

/opt/homebrew/opt/ruby/bin/bundler

If and only if you are using ruby with homebrew, make sure you have it exported to your path: export PATH=/opt/homebrew/opt/ruby/bin:$PATH

Arturo
  • 3,254
  • 2
  • 22
  • 61
-1

TLDR: uninstall ruby & then reinstall it.

Details:

For others using rbenv who have exhausted other ideas, the following worked for me:

  • exit your project directory (e.g. cd /tmp)
  • uninstall ruby (e.g. rbenv uninstall 2.6.6)
  • reinstall ruby (e.g. rbenv install 2.6.6)
  • return to your project directory (cd -)
  • install the RubyGems you desire (e.g. gem install bundler:2.1.4)

In your project directory you will see something like this:

-bash> gem list | grep bundle
bundler (2.1.4, default: 1.17.2)

Outside your project directory (e.g. cd /tmp) you will see something like this:

-bash> gem list | grep bundle
bundler (default: 1.17.2)
user664833
  • 18,397
  • 19
  • 91
  • 140