Running "homebrew upgrade [specific formulae] upgraded a lot more, why?

So I needed to upgrade youtube-dl, and ran brew upgrade youtube-dl. While it was running, homebrew decided it needed to upgrade a lot more stuff, including all of my installed PHP versions... And now, none of them works like they should anymore (error messages in cli, modules not loaded, etc.).

I'm going to go on and probably reformat my machine to have a clean slate, but I wonder why running brew upgrade while explicitely giving the package to upgrade would update others. I understand dependencies, but I highly doubt that youtube-dl is dependent on PHP 7.4 and PHP 8.0, and others.

Is there a flag I missed? Anything else?


Solution 1:

Homebrew FAQ:

Why does brew upgrade also upgrade a bunch of other stuff?

Homebrew doesn’t support arbitrary mixing and matching of formula versions, so everything a formula depends on, and everything that depends on it in turn, needs to be upgraded to the latest version as that’s the only combination of formulae we test. As a consequence any given upgrade or install command can upgrade many other (seemingly unrelated) formulae, if something important like python or openssl also needed an upgrade.

How do I stop certain formulae from being updated?

To stop something from being updated/upgraded:

brew pin <formula>

To allow that formulae to update again:

brew unpin <formula>

Note that pinned, outdated formulae that another formula depends on need to be upgraded when required, as we do not allow formulae to be built against outdated versions. If this is not desired, you can instead brew extract to maintain your own copy of the formula in a tap.

Solution 2:

To see the dependency tree of a Homebrew package, use brew deps --tree <package>:

$ brew deps --tree --include-build youtube-dl
youtube-dl
└── [email protected]
    ├── pkg-config
    ├── gdbm
    ├── mpdecimal
    ├── [email protected]
    ├── readline
    ├── sqlite
    │   └── readline
    └── xz

youtube-dl, php and [email protected] all depend on [email protected]. I could imagine that updating youtube-dl triggered an update of [email protected] which was incompatible with the installed versions of php/[email protected], therefore triggering an update of those packages as well.