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


当前回答

更新Library/Formal/postgresql.rb第8行至

http://ftp2.uk.postgresql.org/sites/ftp.postgresql.org/source/v8.4.6/postgresql-8.4.6.tar.bz2

第9行的MD5

fcc3daaf2292fa6bf1185ec45e512db6

保存并退出。

brew install postgres
initdb /usr/local/var/postgres

现在在这个阶段,您可能会遇到postgresql无法创建共享内存段错误,要解决这个问题,请像这样更新/etc/sysctl.conf:

kern.sysv.shmall=65536
kern.sysv.shmmax=16777216

再次尝试initdb/usr/local/var/postgres,它应该运行平稳。

在启动时运行postgresql

launchctl load -w /usr/local/Cellar/postgresql/8.4.6/org.postgresql.postgres.plist

希望有助于:)

其他回答

解决方案

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

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

以下是我如何降级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

这里的其他答案很好,但如果您需要安装较旧版本的软件包并确保修改了软件包名称,则需要另一种方法。当使用脚本(在我的例子中是PHP构建脚本)时,这一点非常重要,这些脚本使用brew前缀package_name来确定要用于编译的目录。

如果您正在使用brew提取,则会在包名称的末尾添加一个版本,这将中断brew前缀查找。

以下是如何在保持原始软件包名称的同时安装较旧的软件包版本:

# uninstall the newer version of the package that you accidentally installed
brew uninstall --ignore-dependencies icu4c

# `extract` the version you'd like to install into a custom tap
brew tap-new $USER/local-tap
brew extract --version=68.2 icu4c $USER/local-tap

# jump into the new tap you created
cd $(brew --repository $USER/local-tap)/Formula

# rename the formula
mv icu4c@68.2.rb icu4c.rb

# change the name of the formula by removing "AT682" from the `class` definition
# the exact text you'll need to remove will be different
# depending on the version you extracted
nano icu4c.rb

# then, install this specific formula directly
brew install $(brew --repository $USER/local-tap)/Formula/icu4c.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

其他答案都没有充分涵盖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>并升级。