225

我使用Homebrew Cask在 OS X 上安装应用程序。如何升级所有已安装的 casks?

4

23 回答 23

435

现在终于有了 Homebrew Cask 的官方升级机制(见问题 3396的实现)!要使用它,只需运行以下命令:

brew upgrade --cask

但是,这不会更新没有版本信息 ( version :latest) 的 casks 或具有内置升级机制 ( auto_updates true) 的应用程序。要重新安装这些木桶(如果升级可用,则升级它们),运行带有如下--greedy标志的升级命令:

brew upgrade --cask --greedy

于 2015-08-13T17:31:35.923 回答
51

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
于 2016-09-21T09:20:22.617 回答
27

可以列出已安装的木桶:

brew cask list

并强制重新安装木桶:

brew cask install --force CASK_NAME

因此,将第一个命令的输出通过管道传输到第二个命令,我们更新所有的木桶:

brew cask list | xargs brew cask install --force
于 2015-08-16T17:31:32.680 回答
20

用于升级软件包的 Bash 脚本

帕斯卡回答的启发

#!/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

它能做什么

  • 更新 brew/brew cask,清理
  • 阅读木桶清单
  • 检查brew cask info最新版本
  • 如果可用,安装新版本(并删除所有旧版本!)

来源: https ://gist.github.com/atais/9c72e469b1cbec35c7c430ce03de2a6b

一班不耐烦:

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

另存为 /usr/local/bin/cask-upgrade,以便cask-upgrade稍后在本地运行它

于 2016-03-15T01:01:39.513 回答
10

As of December 2017 use: brew cask upgrade

[DEPRECATED since Dec 2017 when Homebrew introduced upgrade command for cask] I simply use the following:

brew cask outdated | xargs brew cask reinstall

于 2017-03-23T09:00:02.950 回答
10

brew cask upgrade

The upgrade command has recently been introduced in Homebrew Cask and should deprecate all the other manual methods described in the other answers.

于 2017-12-03T09:10:45.127 回答
8
brew list --cask | xargs brew upgrade

This cycles through all the applications installed by brew cask and upgrades them one at a time.

brew upgrade --cask

no longer works for me.

于 2021-05-22T12:04:18.667 回答
6

这是我为处理此问题而编写的函数。请注意,我个人不希望它只是盲目地重新安装所有东西,因为我使用的一些木桶需要一段时间才能安装或需要额外的提示。

brew_cask_upgrade() { 
  if [ "$1" != '--continue' ]; then 
    echo "Removing brew cache" 
    rm -rf "$(brew --cache)" 
    echo "Running brew update" 
    brew update 
  fi 
  for c in $(brew cask list); do 
    echo -e "\n\nInstalled versions of $c: " 
    ls /opt/homebrew-cask/Caskroom/$c 
    echo "Cask info for $c" 
    brew cask info $c 
    select ynx in "Yes" "No" "Exit"; do  
      case $ynx in 
        "Yes") echo "Uninstalling $c"; brew cask uninstall --force "$c"; echo "Re-installing $c"; brew cask install "$c"; break;; 
        "No") echo "Skipping $c"; break;; 
        "Exit") echo "Exiting brew_cask_upgrade"; return;; 
      esac 
    done 
  done 
} 
于 2015-08-26T18:54:53.510 回答
5
于 2016-03-31T17:14:39.773 回答
5

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

brew upgrade --cask --greedy
于 2021-04-17T05:57:00.247 回答
4

I think using

brew cask reinstall `brew cask outdated`

will do the trick. This will also help remove the previous version/s of the application and will install the newer version.

于 2016-11-14T06:12:42.810 回答
3

brew upgrade --cask $(brew list --cask)

于 2021-05-15T09:04:33.233 回答
2

改进了deinspanjer 提供的代码,我尝试模仿一个 noop 命令,就像来自 Chocolatey 的那个(choco update --noop / choco outdated)。

https://git.io/vgjiL

#!/bin/sh

fetch(){
    echo "Removing brew cache" 
    rm -rf "$(brew --cache)" 
    echo "Running brew update" 
    brew update 
}

lookup() { 
  for c in $(brew cask list); do 
    brew cask info $c 
  done 
} 

update(){
  var=$( lookup  | grep -B 3 'Not installed' | sed -e '/^http/d;/^Not/d;/:/!d'  | cut -d ":" -f1)
  if [ -n "$var" ]; then
  echo "The following installed casks have updates avilable:"
  echo "$var"
  echo "Install updates now?"
  select yn in "Yes" "No"; do
    case $yn in
      "Yes") echo "updating outdated casks"; break;;
      "No") echo "brew cask upgrade cancelled" ;return;;
      *) echo "Please choose 1 or 2";;
    esac
    done
  for i in $var; do
    echo "Uninstalling $c"; brew cask uninstall --force "$i"; echo "Re-installing $i"; brew cask install "$i"
  done
else
  echo "all casks are up to date"
fi
}

fetch
update

可以看出,我使用的是模块化方法,因为我的用例略有不同。我不想坐在我的电脑前为我安装的每个应用程序输入是/否。虽然没有真正的升级木桶的方法(只是重新安装最新版本),但我首先进行 brew update 以获得实际可用更新的信息

接下来,我循环浏览所有酒桶以显示它们的信息。因为之前做过brew update,所以现在提供了一些cask的最新版本没有安装的信息。

在我的更新方法中,我实际上解析了该特定行的 info 命令:

lookup  | grep -B 3 'Not installed' | sed -e '/^http/d;/^Not/d;/:/!d'  | cut -d ":" -f1

翻译为:“每当您阅读“未安装”行时,请提供上述 3 行信息。然后删除其中包含链接的任何行,同时删除其中包含“:”的行。”

给定 brew cask info 命令的结构,我们最终得到一行(没有版本信息,没有应用程序 URL),它反映了安装它的 cask 的实际名称。

酿造桶信息输出

在我的版本中,此信息现在已打印出来,因此人们可以轻松查看哪些木桶已过时并且可以更新。

在这一点上我做了一个 switch case,因为也许现在还没有足够的时间来更新东西。这取决于您的用例。对我来说,有时我只是想看看有什么新东西(等待一个新版本,一个错误修复),但实际上没有时间更新东西,因为现在我不想关闭我的浏览器等。

因此,如果选择“是”,则将已清理的木桶名称列表提供给更新功能,其中对于确定为过期的每个木桶发出重新安装。

再次感谢 deinspanjer,在尝试为自己解决这个问题时,我总是忘记事先发出 brew update 所以没有“未安装”行来实际解析(我整个方法的基础)。

我希望这可以帮到你。

于 2016-02-18T20:04:59.843 回答
2

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.

于 2017-01-24T10:27:27.643 回答
2

get outdated casks:

brew cask outdated

upgrade cask:

brew cask reinstall outdated-cask

demo script:

$ cat ~/bin/brew_cask_upgrade.sh
#!/bin/bash
red=$(tput setaf 1)
# green=$(tput setaf 2)
reset=$(tput sgr0)

(set -x; brew update;)

for cask in $(brew cask outdated | awk '{print $1}')
do
    echo "${red}update ${cask} ...${reset}."
    (set -x; brew cask install --force "$cask";)
done

echo "${red}brew clean up ...${reset}"
(set -x; brew cask cleanup;)
echo "${red}brew clean up done.${reset}"
于 2017-05-21T04:20:03.867 回答
2
brew cask outdated | xargs brew cask reinstall --force
于 2017-07-30T18:58:17.063 回答
2

Check outdated casks:

brew cask outdated

Upgrading all outdated cask:

brew cask upgrade

If you want upgrade specific cask, just adding cask-name after upgrade (ex: 4k-video-downloader):

brew cask upgrade 4k-video-downloader

于 2019-06-30T08:32:07.357 回答
2
brew cask upgrade $(brew list --cask)
于 2020-08-30T19:14:48.307 回答
2

I have used Homebrew for a while now (it's 2022 now), and here is my favorite one line command to run once everyday while I brew my morning coffee. This is excellent if you have all or most of your applications as casks and managed by Homebrew and you like to have the latest updates for new features & security reasons.

Warnings:

  1. DO NOT use in a work environment where reliability and stability is key. Although having constantly the latest security updates sounds like a good idea, what is not a good idea is getting updates as soon as they come out.
  2. If you are a software developer, modify this command and remove brew upgrade --greedy. This is because it is always better to inspect the versions of the formulae/casks that are outdated before updating for compatibility with your development environments. You are better off upgrading manually the specific formulae/casks that you are sure will not interfere with your projects, and usually that requires inspecting release notes. When separately updating casks/formulae, use brew upgrade cask_name_here.

Here is the command: brew update && brew outdated --greedy && brew upgrade --greedy && brew cleanup

Let's explain what this does.

The brew update command is used to update Homebrew itself, before we do anything else.

The brew outdated --greedy command is used to list all casks/formulae that have updates available. The greedy parameter specifies that apps that auto update themselves and one's flagged with the version:latest should be included to this listing.

The brew upgrade --greedy command is used to update all casks/formulae which were previously listed as outdated. The greedy parameter specifies that apps that auto update themselves and one's flagged with the version:latest should be included in this update process. Be aware that if you see no output in the terminal after running this command it means that there is nothing to update, unlike the brew outdated command this one does not send a message back to the terminal informing users that nothing needs updating.

The brew cleanup command removes old lock files and outdated downloads for all formulae and casks, and remove old versions of installed formulae. In simpler words, old or leftover files from your previous versions of these casks/formulae.

于 2022-01-21T10:59:56.520 回答
1

Based on what i have read i have created a script that will create a file that lists the files to be updated including apps that are defined as latest. You can then modify the file to suit your requirements and install updates using my olinst script.

For more information visit my github.

https://github.com/pacav69/caskroom-offline-install

于 2016-07-01T10:44:36.417 回答
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

于 2016-08-05T21:40:12.467 回答
1

I use

brew cask install --force `brew cask list`
于 2016-10-14T12:41:40.203 回答
1

I work with the fish shell. So I use: brew upgrade (brew list --cask). It works for me.

于 2021-01-08T19:36:50.357 回答