我想创建一个脚本来强制更新过时的 brew 应用程序。
我试过类似的东西,但它不起作用:
var=$(brew cask outdated); for f in $var; do "brew upgrade $var --force"; done
我是 bash 的初学者,我认为我要搜索的内容很简单,但我需要帮助。
最佳答案
2021 更新
2020 年期间 cask
的子命令command 逐渐集成到 Homebrew 的核心中并被弃用。核心命令现在可以对配方和木桶进行操作。要将其范围限制为仅公式或木桶,请添加 --formula
或 --cask
命令行选项。cask
命令已从 Homebrew 版本中完全删除 2.6.0
,于 2020 年 12 月发布。
现在配方和木桶都有统一的流程:
brew update
brew outdated
brew upgrade
第一个命令 ( brew update
) 从 Homebrew 服务器获取有关可用公式和桶的最新版本的信息。第二个命令 (
brew outdated
) 列出过时的安装公式和木桶。添加 --formulae
或 --casks
到命令行以将命令范围限制为公式或木桶。添加 --greedy
到命令行以在其输出中包含标记为“可自动更新”的桶。第三个命令 (
brew upgrade
) 升级 brew outdated
列出的软件包.它还支持上述 brew outdated
的选项。并相应地运作。由于历史原因,保留原始答案和2018年更新。
2018年更新
与此同时,
brew cask upgrade
命令已经实现,可以用来代替 brew cask reinstall
在原始答案中提供的脚本中。它也可以在没有参数的情况下工作并升级
brew cask outdated
显示的所有木桶.它可以代替for
脚本中的块现在变为:# Upgrade Homebrew and the information about formulas
$ brew update
# List the outdated casks (optional)
$ brew cask outdated
# Upgrade all outdated casks
$ brew cask upgrade
附加信息有时,
brew cask outdated
没有列出所有过时的木桶。这是 by design .一些木桶将自己标记为可自动更新,而其他木桶则使用关键字 latest
作为他们的版本。 brew cask outdated
未列出这两类木桶.要列出它们,必须添加 --greedy
brew cask outdated
命令行中的选项:$ brew cask outdated --greedy
此命令在其输出中包含上述木桶。那些有 latest
因为它们的版本不能被检查并且总是被列出,所以只有当它们确实过时时才会检查和列出标记为可自动更新的那些。命令
brew cask upgrade
也接受 --greedy
选项(在内部它使用 brew cask outdated
来查找要升级的软件包列表)。使用它可以确保您的系统是最新的,并且会因重新安装一些未过时的应用程序而产生额外费用。原始答案(2017 年 7 月)
你在混
brew
带有 brew cask
的命令命令,它不能以这种方式工作。Homebrew Cask是 Homebrew 的一个组件允许管理图形应用程序。它开始是原始 Homebrew 的扩展;它现在是
brew
的集成命令. Homebrew本身只管理命令行应用程序。升级命令行程序
升级用
brew
安装的所有过时程序(命令行程序)很简单:# Tell Homebrew to update itself and its taps (repositories of programs)
$ brew update
# List the outdated programs
$ brew outdated
# Upgrade all the outdated programs and their dependencies
$ brew upgrade
brew update
和 brew outdated
步骤是可选的。 brew upgrade
内部电话brew update
如果上次更新发生在过去太多时间。 brew outdated
只列出过时的安装程序;如果您手动进行升级并且不想升级所有内容,这将很有用。在这种情况下,您可以选择要升级的程序并运行 brew upgrade <program>
对于您要更新的每个程序。替换 <program>
用 brew outdated
显示的包名.升级图形程序
目前升级所有过时的图形程序并不是那么简单。过程与上述略有不同。
第一步是运行
brew update
.它更新 Homebrew 代码和点击(tap 是 Homebrew 管理的程序存储库)。 Homebrew Cask 提供子命令 brew cask update
但它只是 brew update
的别名.您可以使用其中任何一个; brew update
是首选,因为它更短。第二步运行
brew cask outdated
.此命令显示由 Cask 管理的过时程序列表,以及已安装的版本和新版本。选项 --quiet
告诉它只显示包名,不显示版本。在第三步中,您将需要它来实现自动化。以下段落自 2018 年起已弃用,当时命令
brew cask upgrade
已实现。上面的“2018 更新”部分描述了新流程。 Unfortunately there is no
brew cask upgrade
command at this moment (it is planned but not implemented yet).brew upgrade
doesn't know how to handle the programs installed bybrew cask
either.
brew cask reinstall
can be used instead of the missingbrew cask upgrade
. Unlikebrew upgrade
, that upgrades all the outdated packages,brew cask reinstall
requires the name of one and only one package. This requires looping through the list returned bybrew cask outdated
.A short shell script that upgrades all outdated programs installed using Homebrew Cask can look like this:
brew update for i in $(brew cask outdated --quiet); do brew cask reinstall $i done
Drawbacks
There are programs that require administrator rights to install drivers or other system components. Some of them ask for your password or for various confirmations using a graphical dialog box.
brew cask
itself sometimes asks for your password in the command line.All these make upgrading the outdated programs automatically not always possible.
You may think that all these can be circumvented using
sudo
. However, the Homebrew developers know better and they programed thebrew
command to display a message and exit when it is executed as root (and this is the right way to do it.)
关于bash - 如何使用 brew 更新应用程序列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45116305/