10

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 && brew upgrade git || brew install git

after doing a brew update, obviously. However, that still seems clumsy to me compared to other package managers.

1
  • 1
    Seems like a pretty decent solution to me. I don’t think there’s an easier or more compact way of doing this.
    – TJ Luoma
    Nov 26, 2019 at 1:21

1 Answer 1

3
+50

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.

1
  • Thanks for confirming that there's indeed no better way, unfortunately.
    – sschuberth
    Nov 26, 2019 at 7:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .