如何在自制程序中安装特定版本的公式?例如,postgresql-8.4.4而不是最新的9.0。


当前回答

家庭酿造最近发生了变化。以前有用的东西现在不管用了。我发现最简单的工作方式(2021 1月)是:

找到我的软件的.rb文件(首先转到公式,找到我需要的文件,然后单击“历史”;对于CMake,这是在https://github.com/Homebrew/homebrew-core/commits/master/Formula/cmake.rb)从修订中选择所需版本,例如3.18.4,单击.rb文件diff(…)右上角的三个点,然后单击Raw。复制URL。取消链接旧版本brew取消链接cmake直接从gitURL安装不再有效(brew-installhttps://raw.githubusercontent.com/Homebrew/homebrew-core/2bf16397f163187ae5ac8be41ca7af25b5b2e2cc/Formula/cmake.rb将失败)相反,下载它并从本地文件curl-O安装https://raw.githubusercontent.com/Homebrew/homebrew-core/2bf16397f163187ae5ac8be41ca7af25b5b2e2cc/Formula/cmake.rb&&brew安装/克马克.rb

瞧!现在可以删除下载的.rb文件。

其他回答

如果无法使用brew search<formula>找到您的版本,您也可以尝试查看公式的提交日志,以找到所需的版本:

下面是通过brew安装旧版本nginx的示例:

ngxnx公式提交日志参见nginx:更新1.6.3瓶装eba75b9a1a474b9fc4df30bd0a32637fa31ec049

从那里,我们可以使用sha和原始git url安装1.6.3:

brew安装https://raw.githubusercontent.com/Homebrew/homebrew/eba75b9a1a474b9fc4df30bd0a32637fa31ec049/Library/Formula/nginx.rb

解决方案

brew extract --version=8.4p1  openssh homebrew/cask
brew install openssh@8.4p1

最新的openssl@8.5p1在我运行brew升级后出现错误,因此我通过上述方式成功地备份到了以前的版本。

其他答案都没有充分涵盖2022年的这一问题,因此我添加了以下说明,这些说明改编自Homebrew维护人员对安装特定酒桶版本的类似问题的回答:https://stackoverflow.com/a/62765875/6310633

卸载公式

brew uninstall <formula>

切换到自制核心回购的克隆,并重置为包含所需版本的提交。

cd "$(brew --prefix)/Library/Taps/homebrew/homebrew-core/Formula"
git log <formula>.rb # examine recent commits for <formula>
git reset --hard <commit-sha> # reset clone to last known-good commit for <formula>

为您的版本签出一个新的分支,这样brew不会在每次命令后自动刷新master,安装您的公式并锁定它。

git checkout -b <formula>-downgrade-<version>
brew install <formula>
brew pin <formula>

清理

git checkout master
brew update

当您准备好升级公式时,您可以像往常一样酿造unpin<formula>并升级。

在最新版本的自制程序(截至本文撰写时为0.9.5)上,将有一个你想要安装的自制桶版本的具体配方。例子:

$ brew search mongodb
mongodb    mongodb24  mongodb26

然后,像正常一样进行brew安装mongodb26。

如果您已经安装了最新版本,请确保取消链接最新版本并链接所需版本:brew unlink mongodb&&brew link mongob26。

以下是我如何降级KOPS(不支持版本控制)

# brew has a git repo on your localhost
cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core

git remote -v
origin  https://github.com/Homebrew/homebrew-core (fetch)
origin  https://github.com/Homebrew/homebrew-core (push)

# find the version of kops.rb you need
git log Formula/kops.rb

# checkout old commit
# kops: update 1.18.1 bottle.
git checkout 2f0ede7f27dfc074d5b5493894f3468f27cc73f0 -- Formula/kops.rb

brew unlink kops
brew install kops

# now we have old version installed
ls -1 /usr/local/Cellar/kops/
1.18.1
1.18.2

which kops
/usr/local/bin/kops
ls -l /usr/local/bin/kops
/usr/local/bin/kops -> ../Cellar/kops/1.18.1/bin/kops
kops version
Version 1.18.1

# revert to the newest version
brew uninstall kops
git checkout -f
brew link kops
kops version
Version 1.18.2