2

How is it possible to ignore a formula by name while upgrading packages in Homebrew with brew upgrade?

Is there a command equivalent to this?:

brew upgrade --ignore <FORMULA>

This Stack Overflow question from 2014 has multiple answers that mention brew pin as a solution, but that feature does not work for casks:

3 Answers 3

1

Does brew know or care that internet thinks that pin is removed? :-)

My brew (3.3.12, last commit 2022-01-26) does know nothing about it. From man brew

pin installed_formula [...]
       Pin the specified formula, preventing them from being upgraded when issuing the brew upgrade
       formula command. See also unpin.

upgrade [options] [outdated_formula|outdated_cask ...]
       Upgrade outdated casks and outdated, unpinned formulae using the same options they were
       originally installed with, plus any appended brew formula options. If cask or formula are
       specified, upgrade only the given cask or formula kegs (unless they are pinned; see pin, unpin).

Documentation seems to be in par with reality as I was able to pin, output pinned list and unpin:

+ > brew pin fzf
+ > brew list --pinned
fzf
+ > brew unpin fzf
+ > brew list --pinned
+ >

Whether pin is what you want or need is another story, but rumors that pin is removed are greatly exaggerated.

1
  • Sorry, I was mistaken when I said "removed". I had meant that pin doesn't work for casks, since there is no --cask option and casks aren't mentioned in pin's --help or the man page.
    – Neil
    Feb 4 at 7:10
1

If you are willing to write some BASH code, this can be done in a one liner using brew list and grep --invert-match:

brew upgrade $(brew list | grep --invert-match <FORMULA>)

Essentially, we just filter the list of packages installed by brew and filter the one called <FORMULA> using grep's inverted matching.

Tested with brew 3.4.3 on GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin20).

1
  • 1
    Just used this, great answer. To be precise I use it for casks, but it would work for formulae just as well. I read an environment variable from a list of casks to be ignored like this: BREW_CASK_IGNORELIST=$(awk '{print $1}' .brew-upgrade-cask-ignorelist | paste -s -d"|" - |sed "s/\|/\\\|/g"); followed by brew upgrade --cask --greedy --force $(brew list --cask | grep --invert-match --regexp $BREW_CASK_IGNORELIST). Mar 27 at 21:19
0

Workaround

You can use buo/homebrew-cask-ugrade, which is a third-party tool with extra cask upgrade features, including pin.

brew tap buo/cask-upgrade    # Install `brew-cask-upgrade`
brew cu pin <CASK_NAME>      # Pin the cask you want

Reason for workaround

It looks like the Homebrew maintainer will not allow pinning of casks, because many casks auto-update, which Homebrew technically can't prevent from happening.

From a comment on homebrew/homebrew-cask: Allow pinning casks #49127:

A huge chunk of casks auto-update and we can’t stop that. So pin would at best be inconsistent and not work in a lot of cases.

3
  • Yes, this is great... but what about casks that doesn't auto-upgrade AND you absolutely DO NOT want to upgrade them (I think of eclipse-java... when using brew upgrade it breaks your install).
    – maxxyme
    Mar 11 at 20:52
  • I'm not sure, but if you want to fix that issue specifically, I'd switch to IntelliJ IDEA. It's much better than eclipse and doesn't have this issue.
    – Neil
    Mar 12 at 5:26
  • Honestly, I tried a few times IntelliJ over the recent years, and I hate it; to me, it's no better than Eclipse, I found it's just another over-complicated bloated IDE... and as I'm used to Eclipse for more than 15 years now, I don't find any reason to change. Or maybe for VS Code... ah ah!!! but we're OT here...
    – maxxyme
    Mar 14 at 11:28

You must log in to answer this question.

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