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


当前回答

我刚刚将一个较旧版本的弹性搜索复制到/usr/local/Cellar/lelasticsearch目录中。

$ mkdir /usr/local/Cellar/elasticsearch/5.4.3/bin
$ cp elasticsearch /usr/local/Cellar/elasticsearch/5.4.3/bin
$ brew switch elasticsearch 5.4.3

就是这样。也许它对任何人都有用。

其他回答

我创建了一个工具来简化这个答案中规定的过程。

要查找a.b.c版本的软件包pkg,请运行:

$ brew-install-specific pkg@a.b.c

这将列出pkg-homebrew公式中提到给定版本的提交及其GitHub URL。

Matching versions:
1. pkg: update a.b.c bottle.
   https://github.com/Homebrew/homebrew-core/commit/<COMMIT-SHA>
2. pkg: release a.b.c-beta
   https://github.com/Homebrew/homebrew-core/commit/<COMMIT-SHA>
3. pkg a.b.c
   https://github.com/Homebrew/homebrew-core/commit/<COMMIT-SHA>

Select index: 

验证来自给定URL的提交,并输入所选提交的索引。

Select index: 2
Run:
  brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/<COMMIT-SHA>/Formula/pkg.rb

复制并运行给定的命令进行安装。

简单工作流

现在Homebrew/versions已经被弃用,Homebrew/core支持一些具有新命名格式的公式版本。

要安装特定版本,例如postgresql 9.5,只需运行:

$ brew install postgresql@9.5

要列出可用版本,请使用@进行搜索:

$ brew search postgresql@
==> Searching local taps...
postgresql@10.1 ✔     postgresql@9.4        postgresql@9.5        postgresql@9.6

这里的其他答案很好,但如果您需要安装较旧版本的软件包并确保修改了软件包名称,则需要另一种方法。当使用脚本(在我的例子中是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

我在这里写了更多。

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

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

$ brew search mongodb
mongodb    mongodb24  mongodb26

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

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