How to undo bundle install?

4.6k views Asked by At

I am working on an Octopress blog, so I set up a separate gemset and did rvm use gemset octopress. It all worked fine. However, I opened a new ZSH tab (I'm on OS X Mountain Lion, if that's relevant) and it fell back to the previous gemset I was using. I didn't know that at that point though, so I ran bundle install. I noticed that it installed all the gems I had already installed in the Octopress gemset, so I figured out what was happening. The question: is there an easy way to undo this bundle install, so that I don't have all these gems in the other gemset, or should I uninstall them manually gem by gem (they are quite a few). Thanks.

2

There are 2 answers

1
mpapis On BEST ANSWER

you can empty gemsets with rvm:

rvm gemset empty

it will remove all gems from the selected gemset, you can also switch temporarly to other gemset with:

rvm @the-other-gemset do rvm gemset empty
0
aercolino On

A couple of days ago I had this same problem (once again) and solved it by writing this command:

$ threshold="20m"; dir="`rvm gemdir`/gems"; find -X "$dir" -type d -maxdepth 1 -mindepth 1 -mtime -"$threshold" | xargs basename | sed -e 's/-\(\([0-9]\{1,\}.\)*[0-9]\{1,\}\)$/ \1/g' -e 's/\(.*\) \(.*\)/gem uninstall \1 --version \2 --executables --ignore-dependencies \&/g'

It generates as many command lines as needed for uninstalling each gem which was added after the given threshold (above is twenty minutes). Then you just copy-and-paste those lines at a command prompt.

Before executing my command:

  1. make sure the current gemset is the one which is messed up
  2. set the threshold to a value that suits your needs

For example, the above command could generate the following lines:

gem uninstall elasticsearch --version 1.0.1 --executables --ignore-dependencies &
gem uninstall elasticsearch-api --version 1.0.1 --executables --ignore-dependencies &
gem uninstall elasticsearch-extensions --version 0.0.14 --executables --ignore-dependencies &
gem uninstall elasticsearch-transport --version 1.0.1 --executables --ignore-dependencies &

If you want some additional info, I posted an article here: http://noteslog.com/post/how-to-undo-a-wrong-bundle-install/