Why does brew cleanup work so well?

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?


I believe it works well since there is a system to version and track every single install and the script can do math to determine the space that it frees up. This is clearly needed if the versions get bumped several times a month and you have dozens of packages installed that get updated regularly. Basically, you're keeping multiple copies of the entire program and everything needed to link to / run / compile the package in many cases.

Why it uses that space is also up to what packages you install and how often they change and what percentage of changes you download / cache / install.

It's an elegant solution so that you can cache the download for machines that have network constraints and when you uninstall the binary or libraries - the cached download remains until you call the brew cleanup only when they need space back urgently - others that have fast network and need space can clean up after every single install if they choose.