homebrew

Configure Homebrew to not delete old versions


When I install a package through homebrew, it removes the old versions.

$ brew upgrade terraform
🍺  /usr/local/Cellar/terraform/0.11.14: 6 files, 42.4MB
Removing: /usr/local/Cellar/terraform/0.11.13... (6 files, 120.6MB)
Removing: /Users/vikas/Library/Caches/Homebrew/terraform--0.11.13.mojave.bottle.tar.gz... (25.4MB)

How can I disable this so that I can switch back to older versions.

$ brew switch [formula] [version]

Solution

  • This behavior can be avoided by setting a variable export HOMEBREW_NO_INSTALL_CLEANUP=TRUE in ~/.bashrc or ~/.zshrc (or specific to your shell).

    Once done, you can check whether it has been applied correctly by:

    $ brew config | grep HOMEBREW_NO_INSTALL_CLEANUP
    HOMEBREW_NO_INSTALL_CLEANUP: TRUE
    $
    

    This was introduced in v1.9.0 and has been documented in man brew as well, but is easy to miss :)

    Unless HOMEBREW_NO_INSTALL_CLEANUP is set, brew cleanup will be run for the installed formulae or, every 30 days, for all formulae
    

    References: - https://github.com/Homebrew/brew/issues/5654