[ruby-on-rails] rails bundle clean

After updating a bundle, you will have some gems that may be obsolete -- since a newer version of that gem has been installed. There is no such command under the bundle executable i.e. bundle clean. How does one get rid of these obsolete gems?

This is an attempt to reduce slug size in my rails app.

This question is related to ruby-on-rails ruby bundler

The answer is


Just remove the obsolete gems from your Gemfile. If you're talking about Heroku (you didn't mention that) then the slug is compiled each new release, just using the current contents of that file.


I assume you install gems into vendor/bundle? If so, why not just delete all the gems and do a clean bundle install?


Just execute, to clean gems obsolete and remove print warningns after bundle.

_x000D_
_x000D_
bundle clean --force
_x000D_
_x000D_
_x000D_


If you're using RVM you may use rvm gemset empty for the current gemset - this command will remove all gems installed to the current gemset (gemset itself will stay in place). Then run bundle install in order to install actual versions of gems. Also be sure that you do not delete such general gems as rake, bundler and so on during rvm gemset empty (if it is the case then install them manually via gem install prior to bundle install).


When searching for an answer to the very same question I came across gem_unused.
You also might wanna read this article: http://chill.manilla.com/2012/12/31/clean-up-your-dirty-gemsets/
The source code is available on GitHub: https://github.com/apolzon/gem_unused


If you are using RVM you can install your gems into gemsets. That way when you want to perform a full cleanup you can simply remove the gemset, which in turn removes all the gems installed in it. Your other option is to simply uninstall your unused gems and re-run your bundle install command.

Since bundler is meant to be a project-per-project gem versioning tool it does not provide a bundle clean command. Doing so would mean the possibility of removing gems associated with other projects as well, which would not be desirable. That means that bundler is probably the wrong tool to use to manage your gem directory. My personal recommendation would be to use RVM gemsets to sandbox your gems in certain projects or ruby versions.


Honestly, I had problems with bundler circular dependencies and the best way to go is rm -rf .bundle. Save yourselves the headache and just use the hammer.


Examples related to ruby-on-rails

Embed ruby within URL : Middleman Blog Titlecase all entries into a form_for text field Where do I put a single filter that filters methods in two controllers in Rails Empty brackets '[]' appearing when using .where How to integrate Dart into a Rails app Rails 2.3.4 Persisting Model on Validation Failure How to fix "Your Ruby version is 2.3.0, but your Gemfile specified 2.2.5" while server starting Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? Rails: Can't verify CSRF token authenticity when making a POST request Uncaught ReferenceError: React is not defined

Examples related to ruby

Uninitialized Constant MessagesController Embed ruby within URL : Middleman Blog Titlecase all entries into a form_for text field Ruby - ignore "exit" in code Empty brackets '[]' appearing when using .where find_spec_for_exe': can't find gem bundler (>= 0.a) (Gem::GemNotFoundException) How to update Ruby Version 2.0.0 to the latest version in Mac OSX Yosemite? How to fix "Your Ruby version is 2.3.0, but your Gemfile specified 2.2.5" while server starting Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? How to update Ruby with Homebrew?

Examples related to bundler

You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory. (mac user) Why won't bundler install JSON gem? Update just one gem with bundler bundle install fails with SSL certificate verification error rails bundle clean Understanding the Gemfile.lock file What does bundle exec rake mean? "Could not find bundler" error How do I specify local .gem files in my Gemfile? What is the best way to uninstall gems from a rails3 project?