The Sharat's

Dependency graph of all installed gems

Read Later on Pocket or Instapaper.

Every other application written using ruby these days seem to come with this installation instruction:

gem install my-super-awesome-app

and then going on to describing how awesome the app is. But, installing the app in the above way installs all its bazillion dependencies, which, unfortunately are not uninstalled when you uninstall this app with

gem uninstall the-same-damn-app

And so, you have huge mess of gems installed which you have no idea why they are there in the first place. Finding out stale gems that are left out because of this can be a pain.

So, I decided a neat flowchart visualising the dependency relationships between all the installed jars would give me a picture. And yes, it did.

Gem dependency graph

Here's how I got the flowchart: (save this in say,


gem list \
    | cut -d\  -f1 \
    | xargs gem dep \
    | awk '\
        BEGIN { print "digraph gems {" } \
        /^Gem / { cur=$2; sub(/-[0-9\.]+$/, "", cur); print "  \"" cur "\";" } \
        ! /^Gem / && $0 != "" { print "  \"" cur "\" -> \"" $1 "\";" } \
        END { print "}" }' \
    | dot -Tpng -o gems.png

Assuming you have GraphViz installed, you can just do

chmod +x

and the graph will be saved in gems.png. Happy gem cleaning :).

Post tagged with

About the author

Hello, I am Shrikant! I love programming and quantitative financial topics. I mostly write about Python, JavaScript and Vim following my work and experiences. Thank you for checking out my blog! Say hello!

Please share your thoughts and feedback in the comments below. If you like my work, consider buying me a coffee, thanks!


← Home

This website uses cookies. By continuing to use this website, you agree to our use of cookies. Know more.