Why does brew cleanup work so well?


(gsquaredxc) #1

I have been referred here by Ask Different. I feel that my question from Ask Different is good enough to copy and paste, however, I completely understand if this is not a very good question, etc. I have learned enough from SE to understand that the new users ask bad/off-topic questions, so I totally understand if you get mad.

As I was going through Brew’s FAQ, I noticed that it said that brew cleanup would cleanup old files. As a usual person would do, I decided to run this command (Ok, maybe most people wouldn’t run random commands they found just for fun). I sit for maybe a minute, and BOOM, This operation has freed approximately 7.2GB of disk space. WOH! After doing some quick research, I didn’t exactly find why this removed 7.2GB from my computer. Brew’s FAQ said:

By default, Homebrew does not uninstall old versions of a formula, so over time you will accumulate old versions.

Most kegs were around 20-80MB when deleted. Some big files you might or might not need, but here you go:

Removing: /usr/local/Cellar/go/1.9.1... (7,639 files, 293.7MB)
Removing: /usr/local/Cellar/go/1.9.2... (7,646 files, 293.9MB)
Removing: /usr/local/Cellar/boost/1.64.0_1... (12,628 files, 395.6MB)
Removing: /usr/local/Cellar/boost/1.65.1... (12,679 files, 401.1MB)
Removing: /usr/local/Cellar/qt/5.9.1... (9,019 files, 277.9MB)
Removing: /usr/local/Cellar/qt/5.9.2... (9,021 files, 279.6MB)
Removing: /usr/local/Cellar/qt/5.9.3... (9,042 files, 279.2MB)
Removing: /usr/local/Cellar/binutils/2.29.1... (113 files, 142.9MB)
Removing: /usr/local/Cellar/gcc/7.1.0... (1,486 files, 283.8MB)
Removing: /usr/local/Cellar/gcc/7.2.0... (1,487 files, 284MB)
Removing: /usr/local/Cellar/wine/2.0.3... (8,252 files, 591.9MB)
Removing: /usr/local/Cellar/wine/2.0.3_1... (8,335 files, 581.6MB)
Removing: /usr/local/Cellar/ghc/8.2.1... (5,583 files, 999.5MB)

Note: The above kegs were picked out, most sit around 20-80MB, as said above.

What does brew store that is cleaned by brew cleanup that is so big?


(Joshua McKinney) #2

Brew installs versions side-by-side, and switches to the new version by linking to it, rather than deleting and overwriting previous versions. brew cleanup removes the previous versions. Next time you run brew upgrade and install a new version of a formula, inspect the differences between in the installs (i.e. what’s under /usr/local/Cellar/<formula>/<version>, and what’s linked in /usr/local/bin etc.)

If you want to avoid losing this space when upgrading (at the expense of not having a fallback version), try brew upgrade --cleanup.

@MikeMcQuaid have you considered making --cleanup behavior the default, or perhaps keeping a single last version instead of multiple? While storage space is less of a primary concern these days, 7GB is a fairly large chunk (just ran a cleanup on my laptop and recovered 4GB, which was nice).


(Mike McQuaid) #3

@joshka We’d need a lot of testing before we can change the default but I’ve opened a PR to allow it to be configured as an environment variable: https://github.com/Homebrew/brew/pull/3913. If you or anyone else experiences breakage of other tools from outside Homebrew from using this: please let us know.


(tgbauer) #4

Maybe could have default be to keep current and 2 prior. This would give a balance between conserving space and being able to roll back if something breaks.