Rails: How can I remove default version of bundler?

24,850

Solution 1

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)

Solution 2

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

Solution 3

gem update --system

This command work for me

After run try this gem list bundler

Solution 4

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

Solution 5

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
Share:
24,850
SST
Author by

SST

Updated on February 11, 2022

Comments

  • SST
    SST about 2 years

    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)