How to uninstall all gems installed using `bundle install`

后端 未结 10 1924
情歌与酒
情歌与酒 2020-12-23 17:09

How can I remove all the gems installed using bundle install in a particular RoR project. I don\'t want to uninstall gems that are used by other projects.

10条回答
  •  天命终不由人
    2020-12-23 17:46

    Found solution for uninstalling all gems except of default:

    Crete delete_gems.rb with

    #!/usr/bin/env ruby
    # Remove all gems EXCEPT defaults :)
    
    `gem list -d`.split(/\n\n^(?=\w)/).each do |data|
      match = data.match(/(?([^\s]+)) \((?.*)\)/)
      name = match[:name]
      versions = match[:versions].split(', ')
    
      if match = data.match(/^.*\(([\d\.]*),? ?default\): .*$/)
        next if match[1].empty? # it's the only version if this match is empty
        versions.delete(match[1] || versions[0])
      end
    
      versions.each { |v| system "gem uninstall -Ix #{name} -v #{v}" }
    end
    

    Run this script:

    sudo chmod 1777 delete_gems.rb
    ./delete_gems.rb
    

    All gems will be removed except of default. Here link on original solution http://zanshin.net/2013/06/10/how-to-delete-all-ruby-gems/

提交回复
热议问题