我使用Homebrew Cask在OS x上安装应用程序,如何升级所有已安装的Cask ?
当前回答
可以列出已安装的桶:
brew cask list
并强制重新安装桶与:
brew cask install --force CASK_NAME
因此,将第一个命令的输出输出到第二个命令中,我们更新了所有的桶:
brew cask list | xargs brew cask install --force
其他回答
我已经使用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请求。
基于@Atais的回答,我将他的逻辑增强为更好的东西。我想要一种方法,在真正强制升级之前,首先检查要升级的包。
$ brew- bucket .sh只是列出了一个类似Homebrew的酿造更新的输出。 上面的列表显示了所有安装的包,绿色的特遣队表示任何未决的更新。 $ brew- bucket .sh upgrade将强制升级这些包。
代码:
# Usage:
#
# $ brew update
# You should execute this first to update everything locally.
#
# $ brew-cask.sh [update]
# This will list all of your cask packages and rather there is an upgrade
# pending with a ✔ checkmark, just like Homebrew does with "brew update".
# The update command is optional, as it doesn't actually do any tracking, there's
# not really anything to "update" with cask. But it keeps with the pattern of
# of Homebrew's "brew update" pattern for those with memory muscle fingers (like me).
#
# $ brew-cask.sh upgrade
# This performs a "brew cask install <cask> --force" of all cask packages that have
# an update pending.
#
# This code was inspired by http://stackoverflow.com/a/36000907/56693
# get the list of installed casks
casks=( $(brew cask list) )
if [[ "$1" == "upgrade" ]]; then
for cask in ${casks[@]}; do
current="$(brew cask info $cask | sed -n '1p' | sed -n 's/^.*: \(.*\)$/\1/p')"
installed=( $(ls /opt/homebrew-cask/Caskroom/$cask))
if (! [[ " ${installed[@]} " == *" $current "* ]]); then
echo "Upgrading $cask to v$current."
(set -x; brew cask install $cask --force;)
else
echo "$cask v$current is up-to-date, skipping."
fi
done
else
echo "Inspecting ${#casks[@]} casks. Use 'brew-cask.sh upgrade' to perform any updates."
for (( i = i ; i < ${#casks[@]} ; i++ )); do
current="$(brew cask info ${casks[$i]} | sed -n '1p' | sed -n 's/^.*: \(.*\)$/\1/p')"
installed=( $(ls /opt/homebrew-cask/Caskroom/${casks[$i]}))
if (! [[ " ${installed[@]} " == *" $current "* ]]); then
casks[$i]="${casks[$i]}$(tput sgr0)$(tput setaf 2) ✔$(tput sgr0)"
fi
done
echo " ${casks[@]/%/$'\n'}" | column
fi
只要安装它(也就是“我现在就需要它!”)
它被检入我的。dotfiles回购;所以,你可以快速地将它安装到你的~/binwith:
$ 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
然后像这样使用它:
$ brew-cask.sh
$ brew-cask.sh upgrade
如果你的路径中没有~/bin,在上面的语句前加上~/bin/。
改进了deinspanjer提供的代码,我尝试模仿一个noop命令,很像来自chocolatey的命令(choco update——noop / choco obsolete)。
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
可以看到,我使用的是模块化方法,因为我的用例略有不同。我不想坐在我的电脑前,对我安装的每个应用程序都输入是/否。虽然没有真正的升级桶的方法(只是重新安装最新版本),我首先做酿造更新的信息,有实际更新可用。
接下来,我循环遍历所有桶以显示它们的信息。因为我之前做了酿造更新,现在提供了一些桶的最新版本没有安装的信息。
在我的update方法中,我实际上为特定的行解析了info命令:
lookup | grep -B 3 'Not installed' | sed -e '/^http/d;/^Not/d;/:/!d' | cut -d ":" -f1
这句话的意思是:“当你读到“未安装”这一行时,给出上面3行信息。然后删除任何有链接的行,也删除有“:”的行。”
考虑到brew cask info命令的结构,我们最终得到一行(没有版本信息,没有应用程序URL),它反映了它安装的桶的实际名称。
酿造桶信息输出
在我的版本中,这些信息现在被打印出来,所以人们可以很容易地看到哪些木桶过时了,并可以更新。
在这里我做了一个切换的例子,因为现在可能没有足够的时间来更新东西。这取决于您的用例。对我来说,我有时只是想看看有什么新的(等待一个新版本,一个错误修复),但实际上没有时间更新东西,因为现在我不想关闭我的浏览器等。
因此,如果有人选择“是”,则将已清理的桶名列表提供给更新函数,其中对于每个被确定为过期的桶,将发布重新安装。
再次感谢deinspanjer,当我试图为自己解决这个问题时,我总是忘记事先发布brew更新,所以没有“未安装”行来实际解析(这是我整个方法的基础)。
我希望这对你们有帮助。
homebrew-cask-upgrade
我认为这是目前为止升级酒桶的最佳方案。 来源:https://github.com/buo/homebrew-cask-upgrade
安装使用
brew tap buo/cask-upgrade
brew update
brew cu
(可选)强制升级过时的应用程序,包括标记为最新的应用程序:
brew cu --all
截至2017年12月使用: 酿造桶升级
[自2017年12月Homebrew为桶引入升级命令以来已弃用] 我简单地使用以下方法:
brew cask outdated | xargs brew cask reinstall
推荐文章
- 警告用户/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文件夹?