install-or-upgrade command #16041

pimlott opened this Issue Nov 13, 2012 · 7 comments

6 participants


brew install fails on already installed formulas. brew upgrade fails on not-installed formulas. This makes it hard to use brew in a script that just wants to bring a formula to the latest version. It has to check whether a formula is installed, then decide whether to install or upgrade it. An install-or-upgrade command would simplify this. In some package systems, the install command actually installs or upgrades, so you don't even need a new command if you go this route.


We've discussed this before, but it is not as simple as it seems.

For example, I often install git from source, and it gets installed into the Cellar as (for example) "git/v1.7.9.1-244-gb0d66b5". If the git formula currently provides, a naive brew install git that auto-upgrades would install and unlink my custom git.

Now one might say that this is a failing of Homebrew's version comparison capabilities. And that specific example could probably be fixed without too much trouble. But there are always going to be cases that it can't handle correctly. So I think it nicely illustrates that Homebrew's flexibility (i.e., that the CLI tools can manage software that was not actually build with Homebrew) sort of demands that these two commands be kept separate.


Addendum: a future incarnation of Homebrew (i.e., 2.0) that enforced reasonable versioning schemes across formula and said explicitly, "if you plan to use the CLI interface to manage external software, be sure to use comparable version numbers," would be able to handle this in a much more sane way. But I think we have existing in this state long enough that making install do upgrades would be a regression for some use cases and I am strongly opposed to such breaking changes.

Now, we can try and make the existing behavior more scriptable. There is a brew which command in contrib that would be useful here. I just tried it, and it is terribly slow, but looking at the code I suspect it could be greatly improved.


@jacknagel brew-wich.rb would be much cleaner and probably faster with the Rack class as in my racknroll branch.

To get the currently linked version: Rack.factory(name).active_keg.version.

Homebrew member

I preferred it when install did upgrade too. Seems like a bit of an edge-case reason to change a common package manager default.


How about, e.g., brew install ruby || brew upgrade ruby? That's shell for: if install fails, then upgrade. Caveats: This prints Error: ruby-1.9.3-p374 already installed if ruby is already installed and again if ruby is already up to date.


We could add a --silent or --q option to suppress output.


Closing since we don't want to add a bare install or upgrade command; will review pull requests for any other ideas presented here.

@adamv adamv closed this Nov 6, 2013
@xu-cheng xu-cheng locked and limited conversation to collaborators Feb 16, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.