39

bundler (2.0.1, default: 1.17.2)

How could I change the default to 2.0.1

Promise Preston
  • 24,334
  • 12
  • 145
  • 143
mmyang
  • 415
  • 1
  • 5
  • 7
  • 1
    When I installed I set gem install --default bundler -v 'X.x.x' but now I have 2 defaults. – Lomefin Mar 10 '19 at 04:05
  • @Lomefin The previous version's gemspec must be removed from the /default directory. Eg `$ mv /usr/share/rvm/rubies/ruby-2.7.0/lib/ruby/gems/2.7.0/specifications/default/bundler-1.17.2.gemspec ../` Note that this command moves the spec from /default into /specifications. It is no longer a default. – AFOC Mar 17 '20 at 19:52
  • I guess you are mistaking what default gems are. They are not indicating default versions. See: https://stdgems.org/. – skalee Sep 26 '20 at 17:04

7 Answers7

48

Following https://bundler.io/guides/bundler_2_upgrade.html#upgrading-applications-from-bundler-1-to-bundler-2, here's what worked for me:

gem install --default bundler
gem update --system
bundle update --bundler
Michaël Witrant
  • 7,525
  • 40
  • 44
Steve K
  • 2,044
  • 3
  • 24
  • 37
19

I had this same concern when trying to setup Bundler gem 2.2.11 as the default gem on my machine.

Here's how I achieved it:

First, I listed and uninstalled all other versions of the Bundler gem because I did not need them:

gem list bundler
gem uninstall bundler

If you encounter an error like this

Gem bundler-2.1.4 cannot be uninstalled because it is a default gem

Simply run the command below to get your ruby installation directory:

gem environment | grep "INSTALLATION DIRECTORY"

This should display an output like this. In my case my ruby version was 2.7.2:

- INSTALLATION DIRECTORY: /home/mycomputer/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0

Next, navigate to the specifications/default directory of the INSTALLATION PATH:

cd /home/mycomputer/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/specifications/default

Remove/delete the bundler.gemspec file that you have there. In my case it was bundler-2.1.4.gemspec, so I ran the command:

rm bundler-2.1.4.gemspec

Next, I installed the Bundler gem 2.2.11 and made it the default gem:

gem install --default bundler -v 2.2.11

Next, I listed my Bundler versions:

gem list bundler

Finally, I updated my gems to use the newly installed Bundler:

gem update --system

That's all.

I hope this helps

Promise Preston
  • 24,334
  • 12
  • 145
  • 143
  • 1
    Why couldn't you just `gem install --default bundler -v 2.2.11` earlier to solve the problem of not being able to remove the newer version? – iconoclast Jul 21 '21 at 23:43
  • 3
    Doing so you end up with to different versions if the bundler gem, but both being marked as default @iconoclast. – Sebastián Palma Aug 24 '21 at 07:58
  • 1
    Doing so results in **two** different versions of the `bundler` gem, both being marked as `default`. (Very sorry... I repeated what was already written because I cannot edit the comment.) Also, you may be able to resolve the issue of two default versions of bundler here: [How can I remove default version of bundler?](https://stackoverflow.com/a/59636874/664833) – user664833 Sep 22 '21 at 00:06
  • I still end up with a different default version when running `bundler -v` after successfully running those instructions. – mduboule Feb 23 '23 at 20:04
18

What helped me is to delete the current default manually from the folder lib\ruby\gems\2.6.0\specifications\default\
and then install fresh bundler as usually
gem install bundler
or as default
gem install --default bundler

Inversion
  • 1,131
  • 13
  • 19
9

You need to remove .spec file to remove the gem.

Steps:

  1. gem env – try to search in provided list under GEM PATHS, in specifications/default
  2. remove there bundler-VERSION.gemspec
  3. install bundler, if you don't have specific: gem install bundler:VERSION --default
dimpiax
  • 12,093
  • 5
  • 62
  • 45
4
gem install --default bundler:<version>
Udit
  • 129
  • 2
  • 6
0

You need to know where the default specs are, so use gem environment to find out.

the steps I used were:

gem environment
# note INSTALLATION DIRECTORY
cd <installation_dir>
cd specifications/default
rm bundler-2.1.4.gemspec
gem install --default bundler -v 2.2.11
stephenr
  • 1,143
  • 7
  • 10
0

Remove all default bundler versions. Commands:

  1. $ gem environment
  2. $ cd INSTALLATION DIRECTORY
  3. $ cd specifications
  4. $ cd default
  5. $ rm bundler version
  6. $ gem install bundler