我使用Homebrew Cask在OS x上安装应用程序,如何升级所有已安装的Cask ?
当前回答
brew cask outdated | xargs brew cask reinstall --force
其他回答
买过时的酒桶:
酿酒桶过时了
升级桶:
酿造桶重新安装过时的桶
演示脚本:
$ 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请求。
带有'auto_updates'或'version:latest'的桶将不会升级;通过——贪婪地升级它们:
brew upgrade --cask --greedy
这是我写的处理这个的函数。注意,我个人不希望它只是盲目地重新安装所有东西,因为我使用的一些桶需要一段时间才能安装或需要额外的提示。
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
}
可以列出已安装的桶:
brew cask list
并强制重新安装桶与:
brew cask install --force CASK_NAME
因此,将第一个命令的输出输出到第二个命令中,我们更新了所有的桶:
brew cask list | xargs brew cask install --force
推荐文章
- 警告用户/local/mysql/data目录不属于mysql用户
- 在Mac OS X上使用鼠标聚焦(加上自动提升)
- 我在哪里可以找到Mac OS X Lion的“make”程序?
- 当我没有Mac的时候,在Mac/Safari上测试web应用程序
- 在Mac上安装MySQL后,使用ALTER USER语句重置MySQL root密码
- my.cnf文件在macOS上的位置
- 如何从Mac OS X上卸载MySQL ?
- 查找当前可执行文件的路径,不包含/proc/self/exe
- 我如何安装imagemagick与自制?
- 在Mac上安装R -警告消息:设置LC_CTYPE失败,使用“C”
- 为什么cURL返回错误“(23)Failed writing body”?
- 节点和错误:EMFILE,打开的文件太多
- 如何使用命令行工具为Mac OS X创建一个漂亮的DMG ?
- 由于环境错误无法安装包:[Errno 13]
- Mac压缩没有__MACOSX文件夹?