At some point a lot of cruft will have accumulated in your homebrew cellar, by cruft I mean old versions of packages you use.
Luckily this can easily be addressed.
$ brew cleanup
The Medium article listed below presents a Bash script to a bit more, I have added my own version here:
#!/bin/bash
brew update
brew upgrade
brew cleanup -s
brew cask cleanup
brew doctor
brew missing
- StackOverflow
- [Medium: "Keeping macOS clean: this is my osx/brew/…update CLI command"