26

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?

6 Answers 6

19

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). Commented 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. Commented 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... Commented 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. Commented 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. Commented Feb 28, 2023 at 8:54
12

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). Commented 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. Commented Apr 28, 2023 at 0:15
8

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.

5
  • Genius answer! Works better than modifying the cask file with a different version number, because that gets clobbered every global update. Commented 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. Commented 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 ? Commented Oct 29, 2023 at 9:03
  • 1
    @TadWohlrapp, I think you are right, but it's easier to brew edit someapp; brew will automatically open the right file for you. Commented Jun 3, 2024 at 2:46
  • Also, re Max's original answer, thank you for making me read the help for brew upgrade --greedy. Turns out, I was too greedy and didn't realize that the default behavior (not specifying that option) is what I actually wanted :) Commented Jun 3, 2024 at 2:48
3

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.

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
  • 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. Commented Feb 4, 2022 at 7:10
-1

Here's a more precise method that does not mismatch on non-casks, forces brew list to output single line and matching exactly on multiple cask names:

brew upgrade --cask $(brew list --cask -1 | grep -Fv -e cask1 -e cask2) 
4
  • The answer needs to explain what the code is doing. Also why differ of the other answer using a single command line. Commented May 12, 2024 at 11:49
  • brew list --cask already provides a newline-separated list, the perl step seems to be a no-op (run diff <(brew list --cask) <(brew list --cask | perl -p -e 's#\s+#\n#g')to check the difference, or lack thereof). Commented May 12, 2024 at 12:15
  • brew list --cask outputs a format with 3 entries per line for me, but I see there is a -1 option to force it to single line, making the perl unnecessary. Commented May 16, 2024 at 23:30
  • Improved and clarified the answer, now also supports multiple cask names. Commented May 16, 2024 at 23:35

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.