Do I have to manually uninstall all dependent gems?

31,421

Solution 1

As far as I know you're correct, there is not an easy way built-in to the gem command to do this.

However, you can check out gem-prune which can help clean up your gem repository after you've removed dm-core.

http://github.com/ddollar/gem-prune/tree/master

Solution 2

gem list | cut -d" " -f1 | xargs gem uninstall -aIx deletes all installed ruby gems!

Solution 3

for gem in `gem list --no-version`; do
  gem uninstall -aIx $gem
done

Works the best for me, not sure why but

gem list | cut -d" " -f1 | xargs gem uninstall -aIx

doesn't work on my system as it still complains...

ERROR:  While executing gem ... (Gem::InstallError)
    cannot uninstall, check `gem list -d some-gem-here`

Solution 4

gem cleanup should do the trick. See here for details.

Solution 5

I ended up making a simple command line tool to gem uninstall dependencies recursively.

I also filed a rubygems issue to gem uninstall dependencies recursively.


That rubygems issue was closed and will not be considered until somebody provides a patch including tests.

Share:
31,421

Related videos on Youtube

Hola
Author by

Hola

Updated on January 29, 2020

Comments

  • Hola
    Hola over 4 years

    I tried to uninstall datamapper using the command gem uninstall dm-core.

    But it seems that a whole bunch of dependent gems also need to be uninstalled.

    C:\>gem uninstall dm-core
    
    You have requested to uninstall the gem:
            dm-core-0.9.11
    dm-migrations-0.9.11 depends on [dm-core (= 0.9.11)]
    dm-cli-0.9.11 depends on [dm-core (= 0.9.11)]
    dm-serializer-0.9.11 depends on [dm-core (= 0.9.11)]
    dm-timestamps-0.9.11 depends on [dm-core (= 0.9.11)]
    dm-aggregates-0.9.11 depends on [dm-core (= 0.9.11)]
    dm-types-0.9.11 depends on [dm-core (= 0.9.11)]
    dm-is-tree-0.9.11 depends on [dm-core (= 0.9.11)]
    dm-observer-0.9.11 depends on [dm-core (= 0.9.11)]
    dm-validations-0.9.11 depends on [dm-core (= 0.9.11)]
    If you remove this gems, one or more dependencies will not be met.
    Continue with Uninstall? [Yn]  n
    ERROR:  While executing gem ... (Gem::DependencyRemovalException)
        Uninstallation aborted due to dependent gem(s)
    

    I tried finding documentation on "gem uninstall" but there doesn't seem to be a way to uninstall the dependencies automatically:

    C:\>gem help uninstall
    Usage: gem uninstall GEMNAME [GEMNAME ...] [options]
    
      Options:
        -a, --[no-]all                   Uninstall all matching versions
        -I, --[no-]ignore-dependencies   Ignore dependency requirements while
                                         uninstalling
        -x, --[no-]executables           Uninstall applicable executables with
    out
                                         confirmation
        -i, --install-dir DIR            Directory to uninstall gem from
        -n, --bindir DIR                 Directory to remove binaries from
            --[no-]user-install          Uninstall from user's home directory
                                         in addition to GEM_HOME.
        -v, --version VERSION            Specify version of gem to uninstall
            --platform PLATFORM          Specify the platform of gem to uninst
    all
    
      Common Options:
        -h, --help                       Get help on this command
        -V, --[no-]verbose               Set the verbose level of output
        -q, --quiet                      Silence commands
            --config-file FILE           Use this config file instead of defau
    lt
            --backtrace                  Show stack backtrace on errors
            --debug                      Turn on Ruby debugging
    
    
      Arguments:
        GEMNAME       name of gem to uninstall
    
      Summary:
        Uninstall gems from the local repository
    
      Defaults:
        --version '>= 0' --no-force --install-dir C:/Ruby18/lib/ruby/gems/1.8
        --user-install
    
    C:\>
    

    Am I missing something?

  • iPadDevloperJr
    iPadDevloperJr over 13 years
    That is actually neat, but more so because I wasn't familiar with the 'cut' command. :) Thanks for showing me!
  • Romain Champourlier
    Romain Champourlier almost 13 years
    Nice! To remove rails3.1.0.rc4 dependencies, I used this one inspired from Bruno's: gem list | grep .rc4 | cut -d" " -f1 | xargs gem uninstall -aIx -v 3.1.0.rc4
  • ma11hew28
    ma11hew28 almost 13 years
    cut is neat! Here is a gem uninstall dependency recursive solution.
  • ma11hew28
    ma11hew28 almost 13 years
    FYI, this doesn't look recursive. It only appears to go down one level, i.e., uninstall the direct dependencies, but not the dependencies of the dependencies, etc. Here is a gem uninstall dependency recursive solution.
  • Nek
    Nek almost 12 years
    OS X Lion version: gem list | cut -d" " -f1 | xargs sudo gem uninstall -aIx
  • Todd A. Jacobs
    Todd A. Jacobs about 10 years
    Calling xargs -n1 will prevent the invocation from stopping when it can't remove default gems for a given Ruby.
  • Segfault
    Segfault about 9 years
    FYI, gem-prune is no longer maintained and not compatible with latest versions.
  • Seph
    Seph about 9 years
    Yup, I will never, ever, ever install anything that has dependencies using gem. Nope.
  • RajaRaviVarma
    RajaRaviVarma over 7 years
    Without deleting the default gems: gem list | cut -d" " -f1 | grep -vE '(rdoc|psych|io-console|bigdecimal|json)' | xargs gem uninstall -aIx
  • buncis
    buncis almost 7 years
    its uninstall almost all my gem, not only that begins with "opener-"
  • Kyrremann
    Kyrremann about 5 years
    This just removed old versions of gems, not dependencies.
  • paul
    paul about 5 years
    It deleted all gems except the few which has default written besides them like bigdecimal (default: 1.3.2).