我使用Homebrew Cask在 OS X 上安装应用程序。如何升级所有已安装的 casks?
23 回答
现在终于有了 Homebrew Cask 的官方升级机制(见问题 3396的实现)!要使用它,只需运行以下命令:
brew upgrade --cask
但是,这不会更新没有版本信息 ( version :latest
) 的 casks 或具有内置升级机制 ( auto_updates true
) 的应用程序。要重新安装这些木桶(如果升级可用,则升级它们),运行带有如下--greedy
标志的升级命令:
brew upgrade --cask --greedy
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
可以列出已安装的木桶:
brew cask list
并强制重新安装木桶:
brew cask install --force CASK_NAME
因此,将第一个命令的输出通过管道传输到第二个命令,我们更新所有的木桶:
brew cask list | xargs brew cask install --force
用于升级软件包的 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
稍后在本地运行它
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
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.
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.
这是我为处理此问题而编写的函数。请注意,我个人不希望它只是盲目地重新安装所有东西,因为我使用的一些木桶需要一段时间才能安装或需要额外的提示。
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
}
Casks with 'auto_updates' or 'version :latest' will not be upgraded; pass --greedy
to upgrade them:
brew upgrade --cask --greedy
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.
brew upgrade --cask $(brew list --cask)
改进了deinspanjer 提供的代码,我尝试模仿一个 noop 命令,就像来自 Chocolatey 的那个(choco update --noop / choco outdated)。
#!/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 所以没有“未安装”行来实际解析(我整个方法的基础)。
我希望这可以帮到你。
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.
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}"
brew cask outdated | xargs brew cask reinstall --force
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
brew cask upgrade $(brew list --cask)
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:
- 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, usebrew 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.
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.
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
I use
brew cask install --force `brew cask list`
I work with the fish shell.
So I use: brew upgrade (brew list --cask)
.
It works for me.