Uninstall all installed gems, in OSX?

后端 未结 13 1192
别那么骄傲
别那么骄傲 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:29

    If you are using Rubygems version 2.1.0 or later, you can try: gem uninstall --all.

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

    The only command helped me to cleanup all gems and ignores default gems, which can't be uninstalled

    for x in `gem list --no-versions`; do gem uninstall $x -a -x -I; done
    
    0 讨论(0)
  • 2020-12-07 07:31

    Use either

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

    or

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

    Depending on what you want, you may need to execute both, because "gem list" and "sudo gem list" provide independent lists.

    Do not mix a normal "gem list" with a sudo-ed "gem uninstall" nor the other way around otherwise you may end up uninstalling sudo-installed gems (former) or getting a lot of errors (latter).

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

    You could also build out a new Gemfile and run bundle clean --force. This will remove all other gems that aren't included in the new Gemfile.

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

    If you like doing it using ruby:

    ruby -e "`gem list`.split(/$/).each { |line| puts `gem uninstall -Iax #{line.split(' ')[0]}` unless line.strip.empty? }"
    

    Cheers

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

    Rubygems >= 2.1.0

    gem uninstall -aIx
    

    If Terminal returns below error

    ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
    

    Then write above command as below

    sudo gem uninstall -aIx
    

    And enter your mac os account password Done!!

    0 讨论(0)
提交回复
热议问题