37

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

12 Answers 12

23

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

  • 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 '16 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 '16 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 '16 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 '16 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 '16 at 9:07
24

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

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

  • 1
    This should be the accepted answer – altabq Mar 20 '18 at 14:09
19

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
12

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.

  • 1
    Well, mind that it will actually reinstall all your apps, not just update the outdated :( – Atais Dec 11 '15 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 – Danijel-James W Apr 29 '16 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 '16 at 19:57
10

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 
  • 4
    This is not true anymore. brew upgrade --all is equivalent to brew upgrade now. Casks are not upgraded by that command. – proski Jan 9 '17 at 23:14
6

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
  • 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. – Danijel-James W Apr 29 '16 at 2:00
  • @Danijel-JamesW Unfortunately it is if you do not want the old version to stay. – Pascal May 14 '16 at 11:43
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

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

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
  • This is unreadable - also needs explanation of what it does – user151019 Apr 28 '16 at 9:27

You must log in to answer this question.

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