How to make brew install a package only if it is not yet installed, and upgrade otherwise? I found it surprisingly hard to make brew either install a package (if it is missing) or upgrade it (if it is already installed). Is there no simple command / arguments to do that?

Based on this answer, I ended up doing (at the example of the git package)

brew ls --versions git &amp;&amp; brew upgrade git || brew install git


after doing a brew update, obviously. However, that still seems clumsy to me compared to other package managers.
Homebrew doesn't support that way of use.

To reduce keypresses you could leverage SHELL-scripting (makes sense to add to your SHELL's .rc-file), say:

brewIn() { if brew ls --versions "$1"; then brew upgrade "$1"; else brew install "$1"; fi }


— Works both in Bash and Zsh. Usage: brewIn …formulae…. But none except this.