How to prevent homebrew from deleting packages automatically?

Almost each time I install something using homebrew, after installing my desired package, it attempts to automatically delete presumably old packages. How can I stop this from occurring? I'm tired of fixing things I'm still using because of whatever logic is encoded into homebrew.

Is there a switch or config setting I can use to disable this behaviour (brew cleanup)?

EDIT Output when I installed pv

user@host:[ 3:03]$ brew install pv
Updating Homebrew...
==> Auto-updated Homebrew!
Updated Homebrew from 35f59eb3c to 4bbe34075.
Updated 7 taps (osrf/simulation, homebrew/cask-versions, homebrew/core, homebrew/cask, homebrew/bundle, homebrew/services and adoptopenjdk/openjdk).
==> New Formulae
apt                      cruft                    fanyi                    joplin-cli               newrelic-infra-agent     ots                      pari-galpol              procps                   singularity              xsel
aws-vault                docuum                   firefoxpwa               libaec                   onedrive                 pari-elldata             pari-seadata             pyoxidizer               spot
bupstash                 eigenpy                  i2c-tools                mailcatcher              opensearch-dashboards    pari-galdata             pari-seadata-big         rsc_2fa                  xauth
==> Updated Formulae
Updated 1023 formulae.
==> Renamed Formulae
prestosql -> trino
==> Deleted Formulae
terraform-provisioner-ansible                                                                                                  tj
==> New Casks
betterdiscord-installer             foxglove-studio                     kdocs                               open-video-downloader               temurin                             transfer                            wifi-explorer-pro
blackhole-64ch                      gosign                              leapp                               shottr                              temurin11                           trezor-suite                        wing-personal
clay                                jiohome                             midi-router-client                  stork                               temurin8                            vym                                 zebra2
==> Updated Casks
Updated 684 casks.
==> Deleted Casks
3cxphone                    anytrans-for-android        deadbeef                    macclean                    phoneclean                  phonetrans                  spectrum                    uberconference              youtube-dl-gui
anytrans                    baiducloud                  imobie-m1-app-checker       phonebrowse                 phonerescue                 postgres-beta               superbeam                   wingpersonal


==> Homebrew was updated to version 3.2.8
The changelog can be found at:
  https://github.com/Homebrew/brew/releases/tag/3.2.8
==> Downloading https://ghcr.io/v2/homebrew/core/pv/manifests/1.6.6-1
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/pv/blobs/sha256:9bb586c4dab67989e7fa800e7c764d1d4ee153db8ad7a5ed3563270ca93a7497
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:9bb586c4dab67989e7fa800e7c764d1d4ee153db8ad7a5ed3563270ca93a7497?se=2021-08-20T10%3A15%3A00Z&sig=w9ejSn6NMsklM8vDAsWuJ1vv5MjiW3cYS4Cca7bPWHI%3D&sp=r&spr=https&sr=b&sv=2
######################################################################## 100.0%
==> Pouring pv--1.6.6.catalina.bottle.1.tar.gz
🍺  /usr/local/Cellar/pv/1.6.6: 5 files, 112.8KB
==> `brew cleanup` has not been run in 30 days, running now...
Removing: /Users/user/Library/Caches/Homebrew/c-ares--1.17.1... (162.9KB)
Removing: /Users/user/Library/Caches/Homebrew/eigen--3.3.9... (1.1MB)
Removing: /usr/local/Cellar/ghostscript/9.52... (1,678 files, 69.3MB)
Error: Directory not empty @ dir_s_rmdir - /usr/local/Cellar/ghostscript/9.52

Making sure autoupdate is not running is a pre-requisite, most people will not have opted in to this, though.

brew autoupdate stop
  • https://docs.brew.sh/Manpage#autoupdate-subcommand-interval-options

Next, you may want to pin your installs as soon as they happen or call for an older version that doesn’t let the auto update run at install time. You are being affected by a change that many people wanted to ensure they get security updates. Assuming pinning works for you, you might still let the rest of the system upgrade regularly and not have to hack the script to change its behavior.

brew pin pv