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


当前回答

brew版本和brew安装https://raw.githubusercontent.com/Homebrew/homebrew-core/现在不支持<COMMIT-HASH>/Formula/<Formula>.rb。

您可以这样尝试:

$ brew extract --version 5.6.2 gradle vitahlin/core
$ brew install gradle@5.6.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

我在这里写了更多。

简单工作流

现在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

自制软件/版本的问题是,必须有人在存储库中列出特定版本的软件才能使用它。此外,由于不再支持brew版本,因此需要另一种解决方案。对于指示使用brew开关的解决方案,这只在您尚未执行brew清理时有效,因为该版本需要存在于您的计算机上。

我遇到了一个问题,想安装一个特定的旧版本的docker机器,它没有在自制软件/版本中列出。我使用下面的方法解决了这个问题,它也适用于任何brew安装的软件。下面的示例将使用docker机器作为我希望从版本0.5.0降级到0.4.1的包。

转到自制公式目录。您可以通过运行brew info[任何包名称]来确定这一点。例如,brew info docker机器给我一行代码路径-/usr/local/Cellar/docker-machine/0.5.0。这告诉我,在我的机器上,自制程序安装在/usr/local和我的公式默认情况下,目录位于/usr/local/Library/Formula找到包的特定公式文件(.rb)。因为我想降级docker-machine,所以可以看到docker-machane.rb文件。获取此公式文件的版本历史记录。输入git-logdocker-machine.rb。这将列出该文件的完整提交历史记录。您将看到如下输出:

    ...more 

    commit 20c7abc13d2edd67c8c1d30c407bd5e31229cacc
    Author: BrewTestBot 
    Date:   Thu Nov 5 16:14:18 2015 +0000

        docker-machine: update 0.5.0 bottle.

    commit 8f615708184884e501bf5c16482c95eff6aea637
    Author: Vincent Lesierse 
    Date:   Tue Oct 27 22:25:30 2015 +0100

        docker-machine 0.5.0

        Updated docker-machine to 0.5.0

        Closes #45403.

        Signed-off-by: Dominyk Tiller 

    commit 5970e1af9b13dcbeffd281ae57c9ab90316ba423
    Author: BrewTestBot 
    Date:   Mon Sep 21 14:04:04 2015 +0100

        docker-machine: update 0.4.1 bottle.

    commit 18fcbd36d22fa0c19406d699308fafb44e4c8dcd
    Author: BrewTestBot 
    Date:   Sun Aug 16 09:05:56 2015 +0100

        docker-machine: update 0.4.1 bottle.

    ...more

棘手的部分是找到所需特定版本的最新提交。在上文中,我可以看出最新的0.4.1版本是用这个提交标记提交的:commit 5970e1af9b13dcbefd281ae57c9ab90316ba423。以上提交开始使用版本0.5.0(git日志条目从最新日期到最早日期列出)。

获取公式文件的早期版本。使用步骤#3中的commit标记(可以使用前6个字符),可以使用以下方法获得公式文件的旧版本:git checkout 5970e1 docker-machine.rb卸载当前软件包版本。只需运行正常的brew命令即可卸载包的当前版本。例如brew卸载docker机器安装较旧的软件包版本现在,您只需运行正常的brew安装命令,它将安装您签出的公式。例如,酿造安装码头机

如果需要,您可能需要使用brew link docker机器重新链接。

如果您想在任何时候恢复到特定软件包的最新版本,请转到Formula目录并在公式文件(.rb)上发出以下命令

git reset HEAD docker-machine.rb
git checkout -- docker-machine.rb

然后,您可以brew卸载docker机器和brew安装docker机器,以获得最新版本,并使其继续下去。

编辑:2021,由于github安装被弃用,这个答案不再起作用。(感谢蒂姆·史密斯的更新)。

安装旧的酿造包版本(Flyway 4.2.0示例)

查找本地自制程序gitdir或本地克隆homebrew/homebrew内核

cd/usr/local/Homebrew/Library/Taps/Homebrew/Homebrew内核/

OR

git克隆git@github.com:Homebrew/Homebrew-core.git

列出所有可用版本

git log master--Formula/flyway.rb

复制所需版本的提交ID并直接安装

brew安装https://raw.githubusercontent.com/Homebrew/homebrew-core/793abfa325531415184e1549836c982b39e89299/Formula/flyway.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