19

I hope there is a command equivalent for casks that works to ignore updates on main line packages.

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:

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

5 Answers 5

13

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.

6
  • 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, 2022 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, 2022 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, 2022 at 11:28
  • Perfect solution! Thanks, worked like a charm to avoid these minor upgrades to libreoffice that took ages for a tool I don't use much. Jul 22, 2022 at 22:23
  • For those wondering what the "cu" in "brew cu pin <CASK_NAME>" is, it is only available once the cask-upgrade tap is installed. Just click the link above for buo/homebrew-cask-ugrade and it explains further.
    – bento
    Feb 28, 2023 at 8:54
8

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).

2
  • 3
    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, 2022 at 21:19
  • @YanickNedderhoff's answer is very close to what I use to prevent certain casks from upgrading, and it works great.
    – Br.Bill
    Apr 28, 2023 at 0:15
7

I discovered a much nicer solution for this:

Add auto_updates true to the cask file that you want to exclude from brew upgrade. This way, the cask is still fully managed by brew and can even be upgraded by using brew upgrade --greedy.


old answer

I found another workaround that will also somewhat work with brew upgrade by simply removing the Cask file from /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Casks.

After removing the file, brew no longer checks the cask for updates and therefore does not even list it in brew upgrade anymore. Keep in mind that this will definitely break all other operations with this cask.

My issue was that I had to pin the version of a JDK as brew would try to upgrade it to a newer version which was not available in production yet. Therefore I deleted the /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Casks/temurin.rb file.

3
  • Genius answer! Works better than modifying the cask file with a different version number, because that gets clobbered every global update.
    – Neil
    Jul 19, 2022 at 15:15
  • Worked to prevent Homebrew from upgrading LibreOffice to 7.5.0 on my macOS 10.13 machine. Before the modification, brew outdated listed libreoffice (7.4.5) != 7.5.0. After the modification, it lists nothing. Feb 6, 2023 at 4:06
  • Asking for clarification: Adding auto_updates true to the cask file means modifying the .json file located in /opt/homebrew/Caskroom/someapp/.metadata/1.2.3/20231029082329.680/Casks/someapp.json ? Oct 29, 2023 at 9:03
2

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
  • 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, 2022 at 7:10
2

A seemingly safer variation of Max's answer is to delete the relevant folders in /opt/homebrew/Caskroom/.

This seems to cause brew to forget it installed them (e.g. they no longer appear in brew list, but without messing with brew's library internals.

You must log in to answer this question.

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