开发者

How do I clean up old github-sourced gems in bundler?

I'm working on a gem and have setup my Gemfile (Rails 3.0.9) to download the latest copy from github. After several updates, I now have a bunch of these different versions installed through bundler, for example:

/Users/jseidel/.rvm/gems/ruby-1.9.2-p180/gems/test_gem-0.0.1/lib/test_gem.rb
/Users/jseidel/.rvm/gems/ruby-1.9.2-p180@rails3/bundler/gems/test_gem-073530fbb227/lib/test_gem.rb
/Users/jseidel/.rvm/gems/ruby-1.9.2-p180@rails3/bundler/gems/test_gem-19ca852f2dbc/lib/test_gem.rb
/Users/jseidel/.rvm/gems/ruby-1.9.2-p180@rails3/bundler/gems/test_gem-1c54d091fa69/lib/test_gem.rb
/Users/jseidel/.rvm/gems/ruby-1.9.2-p180@rails3/bundler/gems/test_gem-2a792620be0e/lib/test_gem.rb
/Users/jseidel/.rvm/gems/ruby-1.9.2-p180@rails3/bundler/gems/test_gem-3dc70da90fcb/lib/test_gem.rb
/Users/jseidel/.rvm/gems/ruby-1.9.2-p180@rails3/bundler/gems/test_gem-4bb5ca8c3fb5/lib/test_gem.rb
/Users/jseidel/.rvm/gems/ruby-1.9.2-p180@rails3/bundler/gems/test_gem-6587eb65715f/lib/test_gem.rb
/Users/jseidel/.rvm/gems/ruby-1.9.2-p180@rails3/bundler/gems/test_gem-6e58646ce11d/lib/test_gem.rb
/Users/jseidel/.rvm/gems/ruby-1.9.2-p180@rails3/bundler/gems/test_gem-725511907cc1/lib/test_gem.rb
/Users/jseidel/.rvm/gems/ruby-1.9.2-p180@rails3/bundler/gems/test_gem-7bc40a7293aa/lib/test_gem.rb
/Users/jseidel/.rvm/gems/ruby-1.9.2-p180@rails3/bundler/gems/test_gem-7fceecaf1539/lib/test_gem.rb
/Users/jseidel/.rvm/gems/ruby-1.9.2-p180@rails3/bundler/gems/test_gem-9ca2049c33f0/lib/test_gem.rb
/Users/jseidel/.rvm/gems/ruby-1.9.2-p180@rails3/bundler/gems/test_gem-b63e6a695990/lib/test_gem.rb
/Users/jseidel/.rvm/gems/ruby-1.9.2-p180@rails3/bundler/gems/test_gem-be3cfbdd01a2/lib/test_gem.rb

bundle exec gem list shows only the latest version:

test_gem (0.3.2)

bundle exec gem uninstall test_gem -v0.1.0 throws an error:开发者_如何学运维

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

gem list -d test_gem shows nothing

bundle exec gem list -d test_gem does show my gem, but no version info

I suppose I could go in and manually delete these entries, but I figure there's a better way to handle this.


Let me show how on mysql2 example:

$ gem list mysql2

mysql2 (0.3.7, 0.3.6, 0.3.2, 0.2.7, 0.2.6)

We can first run gem cleanup in dry-run mode to see what would be removed:

$ gem cleanup -d

Cleaning up installed gems…

...

Dry Run Mode: Would uninstall mysql2-0.2.6

Dry Run Mode: Would uninstall mysql2-0.2.7

Dry Run Mode: Would uninstall mysql2-0.3.2

Dry Run Mode: Would uninstall mysql2-0.3.6

...

Clean Up Complete

Once we are happy with the results, we can run gem cleanup to actually remove the old gems:

$ gem cleanup -v

If you do not see test_gem in gem list -d test_gem* (notice * sign) just try gem cleanup -d maybe it will appear in that listing

in other way - manually - is the best choice!


(sudo) rm -rf /Users/jseidel/.rvm/gems/ruby-1.9.2-p180@rails3/bundler/gems/test*


Bundler provides a way to do this if you must:

bundle clean --force

It is not recommended since the gems may be used by other projects.

Other options are to use RVM gemsets, in which case you can clear out your gemset with:

rvm gemset empty
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜