142

I have global gems and various gemsets. I want to remove all gems of a gemset. Is there a way do to this, besides uninstalling the gemset?

skaffman
  • 390,936
  • 96
  • 800
  • 764
Nerian
  • 15,423
  • 12
  • 65
  • 92

7 Answers7

262

Use the gemset empty command:

rvm gemset empty mygems
Andy Lindeman
  • 11,919
  • 3
  • 34
  • 36
  • 8
    You need to specify the gemset you want to empty. It's not enough just to "rvm use [gemset_name]". You need to "rvm gemset empty [gemset_name]". – refaelos Nov 29 '11 at 10:22
  • I suppose if you have many gems, it could take a while to uninstall them all. – Andy Lindeman Jun 10 '12 at 21:18
  • 14
    Incidentally right now I am able to run `rvm gemset empty` and it clears the current gemset. – Ibrahim Jan 10 '13 at 05:19
17

This command removes all the ruby gems installed locally in 1-step Works well in Ubuntu 10.10

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

PS - removes all local gems. Use sudo accordingly.

lucapette
  • 20,249
  • 5
  • 64
  • 59
Sulabh Jain
  • 388
  • 3
  • 7
  • 2
    gem also has a --no-versions flag, which is nice: `gem list --no-versions | xargs gem uninstall -aIx` – trisweb Nov 20 '12 at 16:32
13

you can also use rvm --force gemset empty

Matilda
  • 1,628
  • 2
  • 22
  • 33
12

rvm gemset empty <gemset name>

This will remove all gems from your mentioned gemset.

Ramiz Raja
  • 5,562
  • 3
  • 24
  • 38
4

rvm gemset empty <gemset> works, but only if you specify a gemset name.

If you want to empty the default gemset, you need to pass an empty string for the gemset name.

rvm gemset empty mygems ""

Craig Walker
  • 47,147
  • 50
  • 150
  • 206
4

Isn't removing all the gems out of a gemset essentially the same operation as deleting a gemset and then adding it back? Why not just do this:

$ rvm gemset mygemset
$ rvm gemset delete mygemset
$ rvm gemset create mygemset
Upgradingdave
  • 12,596
  • 10
  • 61
  • 72
  • Yes, essentially it's the same. But I was wondering if there is a way to do this without deleting the gemset. When you delete a gemset, are the gems removed too or are they saved to a cache? – Nerian Jan 14 '11 at 17:02
  • 1
    I'm pretty sure they're completely removed. For example, I have a gemset named `jruby-1.5.6@radiant`. All the gems are located here: `/Users/dparoulek/.rvm/gems/jruby-1.5.6@radiant`. When I do `rvm gemset radiant`, then it warns you to make sure, and then deletes the entire `/Users/dparoulek/.rvm/gems/jruby-1.5.6@radiant` directory. – Upgradingdave Jan 14 '11 at 17:39
  • This would be about the same I guess. I was looking for an alternative because I wanted to remove all the gems from the global gemset so that I could stop new gemsets from "inheriting" the gems from the global gemset. – Moiz Raja Nov 27 '11 at 20:42
2

This is the safest way to uninstalling all gems of a gemset

Step 1

If you gem version is less then 2.1.

gem update --system

gem --version

Step 2

gem uninstall --all

references

Bhargav Rao
  • 45,811
  • 27
  • 120
  • 136
Mukesh Kumar Gupta
  • 1,397
  • 18
  • 15