Uninstall all installed gems, in OSX?

后端 未结 13 1191
别那么骄傲
别那么骄傲 2020-12-07 07:07

There are instances where I would like to revert and uninstall all previous gem installations.

For instance, I needed to assist a friend migrate their rails developm

相关标签:
13条回答
  • 2020-12-07 07:08

    I did that not too long ago (same poster-child RVM switcher situation):

    gem list | cut -d" " -f1 | sudo xargs gem uninstall -Iax
    

    Takes the list of all gems (incl. version stuff), cuts it to keep only the gem name, then uninstalls all versions of such gems.

    The sudo is only useful if you had gems installed system-wide, and should not be included unless necessary.

    0 讨论(0)
  • 2020-12-07 07:09

    When trying to remove gems installed as root, xargs seems to halt when it encounters an error trying to uninstall a default gem:

    sudo gem list | cut -d" " -f1 | xargs gem uninstall -aIx
    # ERROR:  While executing gem ... (Gem::InstallError)
    #    gem "test-unit" cannot be uninstalled because it is a default gem
    


    This won't work for everyone, but here's what I used instead:

    sudo for gem (`gem list | cut -d" " -f1`); do gem uninstall $gem -aIx; done
    
    0 讨论(0)
  • 2020-12-07 07:20
    gem list --no-version | grep -v -e 'psych' -e 'rdoc' -e 'openssl' -e 'json' -e 'io-console' -e 'bigdecimal' | xargs sudo gem uninstall -ax
    

    grep here is excluding default gems. All other gems will be uninstalled. You can also precede it with sudo in case you get permission issues.

    0 讨论(0)
  • 2020-12-07 07:22

    A slighest different version, skipping the cut step, taking advantage of the '--no-version' option:

    gem list --no-version |xargs gem uninstall -ax
    

    Since you are removing everything, I don't see the need for the 'I' option. Whenever the gem is removed, it's fine.

    0 讨论(0)
  • 2020-12-07 07:24

    And for those of you who are here because you want to remove all gems with a certain prefix (ahem I'm looking at you aws-sdk!) you can run something like this:

    gem list --no-version | grep "aws-sdk-" | xargs gem uninstall -aIx
    

    Obviously put in your query instead of aws-sdk-. You need the -I in there to ignore dependencies.

    Adopted form Ando's earlier answer

    0 讨论(0)
  • 2020-12-07 07:29

    Rubygems >= 2.1.0

    gem uninstall -aIx
    

    a removes all versions
    I ignores dependencies
    x includes executables

    Rubgems < 2.1.0

    for i in `gem list --no-versions`; do gem uninstall -aIx $i; done
    
    0 讨论(0)
提交回复
热议问题