58

Is there any way to upgrade all brew casks? Something like brew cask upgrade?

15 Answers 15

58

As of December, 2017, brew cask upgrade is a thing.

https://github.com/Homebrew/brew/pull/3396

2
  • 15
    brew cask upgrade is deprecated in favor of brew upgrade --cask.
    – Janosh
    Oct 3, 2020 at 10:36
  • 12
    brew upgrade without the --formula or --cask flag now updates both outdated casks and formulae.
    – Janosh
    Oct 3, 2020 at 10:38
24

Bash script to upgrade packages

inspired by Pascal answer

#!/usr/bin/env bash

(set -x; brew update;)

(set -x; brew cleanup;)
(set -x; brew cask cleanup;)

red=`tput setaf 1`
green=`tput setaf 2`
reset=`tput sgr0`

casks=( $(brew cask list) )

for cask in ${casks[@]}
do
    version=$(brew cask info $cask | sed -n "s/$cask:\ \(.*\)/\1/p")
    installed=$(find "/usr/local/Caskroom/$cask" -type d -maxdepth 1 -maxdepth 1 -name "$version")

    if [[ -z $installed ]]; then
        echo "${red}${cask}${reset} requires ${red}update${reset}."
        (set -x; brew cask uninstall $cask --force;)
        (set -x; brew cask install $cask --force;)
    else
        echo "${red}${cask}${reset} is ${green}up-to-date${reset}."
    fi
done

What it does

  • update brew/brew cask, cleanup
  • read the casks list
  • check the brew cask info for the newest version
  • install new version if available (and removes all old versions!)

source: https://gist.github.com/atais/9c72e469b1cbec35c7c430ce03de2a6b

one liner for impatient:

curl -s https://gist.githubusercontent.com/atais/9c72e469b1cbec35c7c430ce03de2a6b/raw/36808a0544628398f26b48f7a3c7b309872ca2c6/cask_upgrade.sh | bash /dev/stdin

save as /usr/local/bin/cask-upgrade, so you can run it locally as cask-upgrade later

7
  • Worked like a charm. Would be nice to query for a list first of out of date packages first though. Easy enough to tweak the script to do it.
    – eduncan911
    Mar 15, 2016 at 16:40
  • Thank you! Have you tried to get this integrated directly into Homebrew Cask? I just converted it to fish and it works for me as well. It also revealed to me that some old versions were still present after I had installed the current ones.
    – Pascal
    May 1, 2016 at 11:55
  • You need to run brew cask uninstall --force before installing the new version if you do not want the old version to stay there.
    – Pascal
    May 14, 2016 at 11:31
  • @Pascal yeah I noticed I have a lot of old versions stacked here too. Soon I will add uninstall command.
    – Atais
    May 16, 2016 at 7:23
  • @Atais does the deinstallation still consistently work for you? Some casks now leave an empty folder with the version number with my script, which messes with the version checking.
    – Pascal
    Nov 13, 2016 at 9:07
23

homebrew-cask-upgrade

I think this is by far the best solution to upgrade the casks.
source: https://github.com/buo/homebrew-cask-upgrade

Installation & usage

brew tap buo/cask-upgrade
brew update
brew cu

(Optional) Force upgrade outdated apps including the ones marked as latest:

brew cu --all
3
  • Very good solution. brew cu -a lists all installed casks and their version (current vs. latest) and allows for updating them individually or all at once. Also well designed and documented (brew help cu).
    – Theo Tiger
    Apr 29, 2020 at 9:13
  • Copy from stackoverflow.com/questions/31968664/…. Don't let the admin's catch you ; )
    – n1000
    Aug 30, 2020 at 10:59
  • Same question same answer
    – Atais
    Aug 30, 2020 at 14:35
11

As the quote in the other answer says, there is currently no way to upgrade all updated casks.

The second part of the answer is wrong, though: brew upgrade --all cannot upgrade casks.

The only way to upgrade all casks is to get a list of the installed casks and force them to be reinstalled - including those that have not changed!

In fish, you could do that like this:

for app in (brew cask list)
    brew cask install --force $app
end

edit:

Atais created a script that works: Bash script to upgrade packages.
Please upvote his answer rather than this one.

3
  • 1
    Well, mind that it will actually reinstall all your apps, not just update the outdated :(
    – Atais
    Dec 11, 2015 at 23:19
  • 1
    To upgrade cask listings, you should run brew cask update then follow the earlier response to upgrade only the packages that are currently out of date here: apple.stackexchange.com/a/231020/49601 Apr 29, 2016 at 2:04
  • @Danijel-JamesW I rolled your change back because it was wrong. It might be the way to do it in other shells, but it isn't in fish.
    – Pascal
    Apr 29, 2016 at 19:57
9

From the homebrew cask documentation:

Since the homebrew-cask repository is a Homebrew Tap, you'll pull down the latest Casks every time you issue the regular Homebrew command brew update. Currently, homebrew-cask cannot always detect if an Application has been updated. You can force an update via the command brew cask install --force. We are working on improving this.

The following should be enough to upgrade both brew formulaes and casks.

brew upgrade --all 
1
  • 5
    This is not true anymore. brew upgrade --all is equivalent to brew upgrade now. Casks are not upgraded by that command.
    – proski
    Jan 9, 2017 at 23:14
6

Casks with 'auto_updates' or 'version :latest' will not be upgraded; pass --greedy to upgrade them:

brew upgrade --cask --greedy
1
  • 2
    If you came here in 2022 it is the answer Feb 15, 2022 at 6:55
5

Here's what I have in my .bash_profile that I run to do a full upgrade pass of homebrew. I "pin" a couple items to keep gigantic downloads from being repeatedly fetched for every update, because their versions are always "latest" or they shouldn't be upgraded.

boop() {
  brew update && brew upgrade && brew cleanup \
    && cask-upgrade && cask-retire && brew cask cleanup \
      && brew doctor && brew cask doctor
}

__is_pinned() {
  local pinned=";pixate-studio;sketchup;skype;"
  [[ *";${1};"* != "${pinned}" ]] && return 0 || return 1
}

cask-upgrade() {
  while read -r; do
    reply=(${REPLY})
    name="${reply[0]}"
    vers="${reply[1]}"
    if ! __is_pinned "${name}"; then
      if [[ "${vers}" == "latest" ]]; then
        brew cask install "${name}" --force
      else
        brew cask install "${name}" 2> >(grep -v "re-install")
      fi
    fi
  done < <(brew cask list --versions)
}

cask-retire() {
  room="/opt/homebrew-cask/Caskroom"
  while read -r; do
    reply=(${REPLY})
    name="${reply[0]}"
    vers="${reply[1]}"
    if ! __is_pinned "${name}"; then
      for inst in $(ls "${room}/${name}"); do
        if [[ "${inst}" != "${vers}" ]]; then
          echo "Removing ${name} version ${inst}"
          rm -r "${room}/${name}/${inst}"
        fi
      done
    fi
  done < <(brew cask list --versions)
}
2

To reinstall brew cask apps in zsh:

brew cask update;

for app in $(brew cask list); do
    brew cask uninstall --force ${app}
    brew cask install --force ${app}    
done
2
  • This isn't very good for users who might have a lot of brew cask installations that require user input (e.g. - quartz). Also, it's not necessary to uninstall every application before re-installing it. Ideally you should also run an update like brew cask update first. Apr 29, 2016 at 2:00
  • @Danijel-JamesW Unfortunately it is if you do not want the old version to stay.
    – Pascal
    May 14, 2016 at 11:43
2

This would probably be more appropriate as a comment, but I don't have enough reputation to leave one, so...

As of this writing, homebrew-cask has its own upgrade system, and so the third-party scripts and tools are no longer required.

To list outdated casks: brew cask outdated

To upgrade all outdated casks: brew cask upgrade

1

This has really irked me so I created this script to update all Brew apps and allow the user to choose which Cask apps to update. You can exclude apps from consideration too.

https://github.com/derrekyoung/ScriptsAndUtils/blob/master/brew-cask-upgrade.sh

1

I recommend @eduncan911's answer in the counterpart question on Stack Overflow.

In short:

  • $ brew-cask.sh just lists an output similar to Homebrew's brew update. the list above shows all packages installed, with a green indicating any pending updates.
  • $ brew-cask.sh upgrade will force the upgrade of those packages.

Install from his repo with:

$ curl -L https://raw.githubusercontent.com/eduncan911/dotfiles/master/bin/brew-cask.sh --create-dirs -o ~/bin/brew-cask.sh
$ chmod 755 ~/bin/brew-cask.sh

Then use it like this:

$ brew-cask.sh
$ brew-cask.sh upgrade
1

I made such script by myself. Please look at the github https://github.com/pesh1983/brew_cask_upgrade. It has pretty good description, but if you have any additional question, feel free to ask me. It does fair upgrade: uninstall and install, so any necessary cleanup will be performed by 'brew' itself.

1

Similar to @DarrenPMeyer, this would probably be more appropriate as a comment, but I too don't have enough reputation to leave one, so...

Adding on to @Raúl Cuza and @DarrenPMeyer's comments, some casks are considered auto-updating, but in my experience, many typically do not update promptly.

One can do brew cask upgrade --greedy or brew cask outdated --greedy to include those auto-updating casks.


Also, if you wanted to upgrade your casks automatically, I would suggest first installing homebrew-cask-upgrade:

brew tap buo/cask-upgrade
brew update
brew cu

then scheduling brew cu --all --cleanup --yes in your crontab (we must use root's crontab because brew casks often need root permission):

sudo crontab -e

and write:

MAILTO=""
#!/bin/sh
PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin
40 15 * * * brew cu --all --cleanup --yes
1
  • 2
    the greedy argument works well.
    – WIZARDELF
    Apr 5, 2020 at 2:51
1

since homebrew version 2.6.0 brew cask upgrade is deprecated and was replaced with brew upgrade --cask (March 2021)

https://brew.sh/2020/12/01/homebrew-2.6.0/

0
for app in $(brew cask list); do
    cver="$(brew cask info "${app}" | head -n 1 | cut -d " " -f 2)"
    ivers=$(ls -1 "/opt/homebrew-cask/Caskroom/${app}/.metadata/" | tr '\n' ' ' | sed -e 's/ $//')
    aivers=(${ivers})
    nvers=$(echo ${#aivers[@]})
    echo "[*] Found ${app} in cask list. Latest available version is ${cver}. You have installed version(s): ${overs}"
    if [[ ${nvers} -eq 1 ]]; then
        echo "${ivers}" | grep -q "^${cver}$" && { echo "[*] Latest version already installed :) Skipping changes ..."
        continue; }
    fi
    echo "[+] Fixing from ${ivers} to ${cver} ..."
    brew cask uninstall "${app}" --force
    brew cask install "${app}"
done
1
  • This is unreadable - also needs explanation of what it does
    – mmmmmm
    Apr 28, 2016 at 9:27

You must log in to answer this question.

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