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


当前回答

我认为使用

brew cask reinstall `brew cask outdated`

会成功的。这也将有助于删除应用程序的以前版本,并安装新版本。

其他回答

买过时的酒桶:

酿酒桶过时了

升级桶:

酿造桶重新安装过时的桶

演示脚本:

$ 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}"

我已经使用Homebrew有一段时间了(现在是2022年),下面是我最喜欢的一行命令,每天在我煮早上的咖啡时运行一次。如果您将所有或大部分应用程序作为桶,并由Homebrew管理,并且出于新功能和安全原因希望进行最新更新,那么这是非常好的。

警告:

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

下面是命令:brew update && brew obsolete -greedy && brew upgrade -greedy && brew cleanup

让我们来解释一下这是做什么的。

brew update命令用于在执行其他操作之前更新Homebrew本身。

brew outdated——greedy命令用于列出所有更新可用的酒桶/公式。贪心参数指定自动更新自己的应用程序和标记为version:latest的应用程序应该包含在这个列表中。

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.

brew cleanup命令删除所有公式和桶的旧锁文件和过时下载,并删除已安装公式的旧版本。简单地说,就是这些桶/公式以前版本的旧文件或剩余文件。


开发人员和工作环境的潜在解决方案 如果你想使用如上所述的这个解决方案,并且在Homebrew中有关键的依赖关系,有一个解决方案:

brew pin [package_name_here]

当所有包都用上面的命令更新时,pin命令将停止Homebrew更新指定的包。有关更多信息,这里是将该功能添加到Homebrew的pull请求。

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

它的作用

更新酿造/酿造桶,清理 读酒桶清单 检查酿造桶信息的最新版本 如果可用,请安装新版本(并删除所有旧版本!)

来源: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/桶-upgrade,以便稍后在本地以桶-upgrade的形式运行

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

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 
} 

这样的剧本是我自己做的。请查看github https://github.com/pesh1983/brew_cask_upgrade。它有很好的描述,但如果你有任何其他问题,请随时问我。它进行了公平的升级:卸载和安装,因此任何必要的清理将由“brew”本身执行。