Davide Targa website

Programming, web development and open source

Remove All Gems Inside a Rvm Gemset

Sometimes you may need to uninstall all the rubygems inside a gemset.

The problem is that the only way to uninstall all the gems inside a RVM gemset is to use the following command:

$ rvm use 1.9.2@my-gemset
Using /home/user/.rvm/gems/ruby-1.9.2-p180 with gemset my-gemset
$ gem uninstall gem1 gem2 gem3 ...

A bit boring, don’t you think?

One way to automate this process is through the following command:

gem uninstall `gem list | cut -d" " -f1 | tr '\n' ' '`

If you don’t use RVM to manage different Ruby versions, maybe you have to change the command above in something like this:

sudo gem uninstall `sudo gem list | cut -d" " -f1 | tr '\n' ' '`

Pay attention to copy all the ` characters.

In this way you can uninstall all the gems only with one command.

Hope this helps :–)