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


当前回答

如果无法使用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

其他回答

家庭酿造最近发生了变化。以前有用的东西现在不管用了。我发现最简单的工作方式(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文件。

⚠ 这个答案在2020年12月后不再有效:在HomeBrew 2.7.0中禁用了brew开关(2.6.0中已弃用)


对于2.7之前的Homebrew版本:

现在有一种更简单的方法来安装以前安装的公式的旧版本。简单使用

brew switch [formula] [version]

例如,我定期在Node.js 0.4.12和0.6.5之间切换:

brew switch node 0.4.12
brew switch node 0.6.5

由于brew开关只是更改符号链接,所以速度非常快。请参阅外部命令下Homebrew Wiki的更多文档。

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

UPDATE:此方法已弃用,不再有效。

此方法导致错误:不支持从GitHub提交URL安装mysql!brew将mysql提取到GitHub上的稳定水龙头。(用法错误)

$ brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/c77882756a832ac1d87e7396c114158e5619016c/Formula/mysql.rb
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core and homebrew/cask).

...

Traceback (most recent call last):
    9: from /usr/local/Homebrew/Library/Homebrew/brew.rb:122:in `<main>'
    8: from /usr/local/Homebrew/Library/Homebrew/cmd/install.rb:132:in `install'
    7: from /usr/local/Homebrew/Library/Homebrew/cli/parser.rb:302:in `parse'
    6: from /usr/local/Homebrew/Library/Homebrew/cli/parser.rb:651:in `formulae'
    5: from /usr/local/Homebrew/Library/Homebrew/cli/parser.rb:651:in `map'
    4: from /usr/local/Homebrew/Library/Homebrew/cli/parser.rb:655:in `block in formulae'
    3: from /usr/local/Homebrew/Library/Homebrew/formulary.rb:351:in `factory'
    2: from /usr/local/Homebrew/Library/Homebrew/formulary.rb:138:in `get_formula'
    1: from /usr/local/Homebrew/Library/Homebrew/formulary.rb:142:in `klass'
/usr/local/Homebrew/Library/Homebrew/formulary.rb:227:in `load_file': Invalid usage: Installation of mysql from a GitHub commit URL is unsupported! `brew extract mysql` to a stable tap on GitHub instead. (UsageError)
    12: from /usr/local/Homebrew/Library/Homebrew/brew.rb:155:in `<main>'
    11: from /usr/local/Homebrew/Library/Homebrew/brew.rb:157:in `rescue in <main>'
    10: from /usr/local/Homebrew/Library/Homebrew/help.rb:64:in `help'
     9: from /usr/local/Homebrew/Library/Homebrew/help.rb:83:in `command_help'
     8: from /usr/local/Homebrew/Library/Homebrew/help.rb:103:in `parser_help'
     7: from /usr/local/Homebrew/Library/Homebrew/cli/parser.rb:302:in `parse'
     6: from /usr/local/Homebrew/Library/Homebrew/cli/parser.rb:651:in `formulae'
     5: from /usr/local/Homebrew/Library/Homebrew/cli/parser.rb:651:in `map'
     4: from /usr/local/Homebrew/Library/Homebrew/cli/parser.rb:655:in `block in formulae'
     3: from /usr/local/Homebrew/Library/Homebrew/formulary.rb:351:in `factory'
     2: from /usr/local/Homebrew/Library/Homebrew/formulary.rb:138:in `get_formula'
     1: from /usr/local/Homebrew/Library/Homebrew/formulary.rb:142:in `klass'
/usr/local/Homebrew/Library/Homebrew/formulary.rb:227:in `load_file': Invalid usage: Installation of mysql from a GitHub commit URL is unsupported! `brew extract mysql` to a stable tap on GitHub instead. (UsageError)

我尝试使用推荐的命令进行安装,但它在MySQL 5.7.10的这个特定实例中不起作用。你可能会有更好的运气与更新的公式。

$ brew extract --version=5.7.10 mysql homebrew/cask
==> Searching repository history
==> Writing formula for mysql from revision 0fa511b to:
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Formula/mysql@5.7.10.rb

$ 

$ brew install /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Formula/mysql@5.7.10.rb
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
Updated 1 formula.
Error: undefined method `core_tap?' for nil:NilClass

Error: Failed to load cask: /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Formula/mysql@5.7.10.rb
Cask 'mysql@5.7.10' is unreadable: wrong constant name #<Class:0x00007f9b9498cad8>
Warning: Treating /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Formula/mysql@5.7.10.rb as a formula.
==> Installing mysql@5.7.10 from homebrew/cask
==> Downloading https://homebrew.bintray.com/bottles/cmake-3.19.4.big_sur.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/278f2ad1caf664019ff7b4a7fc5493999c06adf503637447af13a617d45cf484?response-content-disposition=attachment%3Bfilenam
######################################################################## 100.0%
==> Downloading https://downloads.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.bz2
==> Downloading from https://phoenixnap.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.bz2
######################################################################## 100.0%
==> Downloading https://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.10.tar.gz

curl: (22) The requested URL returned error: 404 Not Found
Error: Failed to download resource "mysql@5.7.10"
Download failed: https://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.10.tar.gz

您可以在上面的路径中修改公式(用ruby编写),以尝试实现所需的结果(例如,在最近的macOS版本上安装MySQL 5.7.10)。


您可以使用识别公式和公式历史记录中与您要安装的软件包版本匹配的特定提交的策略。

去https://github.com/Homebrew/homebrew-core按键盘上的t启动文件查找器。确定一个看起来最相关的公式,可能是:formula/mysql.rb,将您带到forumla文件位置:https://github.com/Homebrew/homebrew-core/blob/master/Formula/mysql.rb.单击历史记录按钮查看修订历史记录,该按钮位于https://github.com/Homebrew/homebrew-core/commits/master/Formula/mysql.rb.如果您对MySQL 5.7.10感兴趣,可以单击5.7.11之前的最新版本,该版本导航到GitHub提交:

https://github.com/Homebrew/homebrew-core/commit/c77882756a832ac1d87e7396c114158e5619016c#Formula/mysql.rb

注意:如果提交历史没有加载到浏览器中,您可能需要根据GitHub的建议在控制台中查看提交历史。如果您有兴趣在GitHub上看到提交,请在URL中替换上面的提交SHA。或者,跳到下面的步骤7。

应用提交后,单击“查看”按钮查看mysql.rb文件的源代码。然后单击“原始”按钮查看原始源。复制URL。或者,使用mysql.rb文件名自己构建URL,以标识您的公式和该公式的特定版本(由以下URL中的commmit SHA标识)。

https://raw.githubusercontent.com/Homebrew/homebrew-core/c77882756a832ac1d87e7396c114158e5619016c/Formula/mysql.rb

使用$brew Install[步骤7的URL]安装它$brew安装https://raw.githubusercontent.com/Homebrew/homebrew-core/c77882756a832ac1d87e7396c114158e5619016c/Formula/mysql.rb

基于@tschundee和@Debilski的更新1所描述的工作流,我自动化了该过程,并在此脚本中添加了清理。

下载它,将其放到您的路径中,然后brewv<formula_name><wanted_version>。对于特定OP,它将是:

cd path/to/downloaded/script/
./brewv postgresql 8.4.4

:)