Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find unused gems and cleanup gemfile

I'm looking for simple, but good way to cleanup gemfile and make rails startup faster. How can I get a list of all required gems vs all loaded gems.

like image 232
Seva Feldman Avatar asked Oct 03 '13 19:10

Seva Feldman


3 Answers

bundle clean --force will remove old gems (or older versions of currently-used gems) previously installed, but not currently being used in your current Gemfile.lock manifest.

like image 79
changingrainbows Avatar answered Sep 22 '22 09:09

changingrainbows


First, if you want to check what are the gems used by your project, I invite you to run gem server in your project folder root, then go to http://0.0.0.0:8808/

You will be able to understand the dependencies of all the gems your project is using. It will also show you all versions of the same gem.

To remove old versions of gems you can run as @changingrainbows mention bundle clean --force

After this step run your gem server again and watch the result, a clean and understandable gem list with all dependencies.

like image 45
Titouax Avatar answered Sep 22 '22 09:09

Titouax


It depends what you're after here.

If you're looking to remove old, unused gem versions, then bundle clean.

If you've been adding gems as you develop and have lost track of the ones you actually use, and have good test coverage, then try this answer.

If you want to reduce the number of gems rails pulls in at startup to the bare minimum, try gem_bench.

like image 41
fakeleft Avatar answered Sep 21 '22 09:09

fakeleft