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.
You can use (like Tobias says, if you are using RVM)
rvm gemset empty [gemset]
Directly on the gemset, for example
rvm gemset empty 2.0.0@server
If you're using rvm, you could of course just uninstall and reinstall the version of ruby under which you've installed the gems, i.e.
% rvm use
Using /home/ubuntu/.rvm/gems/ruby-2.2.1
% rvm uninstall 2.2.1
ruby-2.2.1 - #removing rubies/ruby-2.2.1..
ruby-2.2.1 - #removing default ruby interpreter.............
% rvm install 2.2.1
Searching for binary rubies, this might take some time.
Found remote file https://rvm_io.global.ssl.fastly.net/binaries/ubuntu/14.0/x86_64/ruby-2.2.1.tar.bz2
Checking requirements for ubuntu.
Requirements installation successful.
ruby-2.2.1 - #configure
ruby-2.2.1 - #download
ruby-2.2.1 - #validate archive
ruby-2.2.1 - #setup
ruby-2.2.1 - #gemset created /home/ubuntu/.rvm/gems/ruby-2.2.1@global
ruby-2.2.1 - #importing gemset /home/ubuntu/.rvm/gemsets/global.gems..............................
ruby-2.2.1 - #generating global wrappers........
ruby-2.2.1 - #gemset created /home/ubuntu/.rvm/gems/ruby-2.2.1
ruby-2.2.1 - #importing gemsetfile /home/ubuntu/.rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.2.1 - #generating default wrappers........
and now you have a ruby environment clean of any installed gems.
Since we're using ruby you could do something like this I guess:
bundle list | ruby -e 'ARGF.readlines[1..-1].each {|l| g = l.split(" "); puts "Removing #{g[1]}"; `gem uninstall --force #{g[1]} -v #{g[2].gsub(/\(|\)/, "")}`; }'
NOTE: Only lightly tested.
There's no one simple way to remove all gems - let alone removing those within a specific bundle. You could try some of these suggestions: Uninstall all installed gems, in OSX?
Adapt to the bundle show
command instead of gem list
For the future, try this approach:
If you install your bundle locally like the example below, the gems won't be installed in your global gem directory. Then you can easily delete the installation folder to delete all gems of the bundle.
# install gems to project_root/vendor/bundle
bundle install --path vendor/bundle --without test
The path option is saved to .bundle/config just like all others and any subsequent bundle install
calls will use it unless you set it to something else or remove it from the config!