Search code examples
ruby-on-railsrubygemsgemfile

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.


Solution

  • I think it is impossible. When your APP starts it loads gems from Gemfile.lock but it does not know if they (gems) are needed in your code or not. The APP inform you by raising an exception When something calls a class or method that is undefined if some needed gem is missed (if you remove it from Gemfile), but this can happen at any moment (not during starting your APP).

    So if you are looking the way to clean up your gem list I think the best way to do it manually (I know it is not easy way). Analyse each gem to find out what functionality it provides and decide (or find in your code) if it is needed or not. Additionally tests (if you have them) should help you a lot.