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


当前回答

我决定,违背我更好的判断,为Maven 3.1.1创建一个公式,而自制程序/版本没有。要执行此操作:

我在github上分叉了自制程序/版本。我从$(brew-prefix)/Library/Taps符号链接到我的fork的本地工作副本。我将其称为我的自制程序/版本。我通过将公式指定为我的自制程序/版本/<公式>进行测试。我向自制程序/版本发送了新公式的拉取请求。

Yay.

其他回答

我决定,违背我更好的判断,为Maven 3.1.1创建一个公式,而自制程序/版本没有。要执行此操作:

我在github上分叉了自制程序/版本。我从$(brew-prefix)/Library/Taps符号链接到我的fork的本地工作副本。我将其称为我的自制程序/版本。我通过将公式指定为我的自制程序/版本/<公式>进行测试。我向自制程序/版本发送了新公式的拉取请求。

Yay.

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

最接近@Lance的答案,但这对我来说并不奏效,在2023年,使用M1macOS13并尝试安装特定版本的opencv@4.

底线是:您应该用brew的GitHub repo中找到的远程opencv.rb文件的内容覆盖本地opencv.r文件的内容,该文件对应于您要安装的opencv版本。

本质上,我们希望更新包的.rb文件中的url和sha256。但是sha256在opencvReleases Github页面上不可用,在本地创建sha256会给我带来校验和错误。但是从提交历史记录中获取.rb文件可以解决这个问题。

分解:5个简单步骤

首先卸载包:brew卸载opencv@4查找要安装的软件包的正确版本的.rb文件在Github上的Homebrew>Homebrew core>Formula下搜索在opencv.rb文件的历史记录中:https://github.com/Homebrew/homebrew-core/commits/master/Formula/opencv.rb选择与所需版本相对应的提交,例如opencv:update 4.6.0_1 bottle。和查看文件。复制/下载文件的内容在系统上打开.rb文件:breweditopencv@4用从Github下载的文件替换此文件的内容使用.rb文件路径再次安装软件包:brew Install/opt/homebrew/Library/Taps/homebrew/homebrew core/Formula/oppencv.rb

这对我来说非常有效,然而,@Lance使用brew install的回答给出了一个错误:您的命令行工具(CLT)不支持macOS 13。

其他答案对我来说也不管用。

我刚刚将一个较旧版本的弹性搜索复制到/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

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

更新日期:2015年1月15日

查找所需软件和版本的提交历史记录。例如,我需要从docker版本1.4.1切换到1.3.3:https://github.com/Homebrew/homebrew-core/commits/master/Formula/docker.rb使用此按钮查看文件:单击“原始”按钮:从地址栏复制URL(本例中为docker.rb URL)brew install<url>(可能必须首先brew unlink,例如brew unlinkdocker)酿造开关装卸工1.3.3切换回码头1.4.1酿造切换码头1.4.1

根据这一要点

brew update
brew versions FORMULA
cd `brew --prefix`
git checkout HASH Library/Formula/FORMULA.rb  # use output of "brew versions"
brew install FORMULA
brew switch FORMULA VERSION
git checkout -- Library/Formula/FORMULA.rb    # reset formula

## Example: Using Subversion 1.6.17
#
# $ brew versions subversion
# 1.7.3    git checkout f8bf2f3 /usr/local/Library/Formula/subversion.rb
# 1.7.2    git checkout d89bf83 /usr/local/Library/Formula/subversion.rb
# 1.6.17   git checkout 6e2d550 /usr/local/Library/Formula/subversion.rb
# 1.6.16   git checkout 83ed494 /usr/local/Library/Formula/subversion.rb
# 1.6.15   git checkout 809a18a /usr/local/Library/Formula/subversion.rb
# 1.6.13   git checkout 7871a99 /usr/local/Library/Formula/subversion.rb
# 1.6.12   git checkout c99b3ac /usr/local/Library/Formula/subversion.rb
# 1.6.6    git checkout 8774131 /usr/local/Library/Formula/subversion.rb
# 1.6.5    git checkout a82e823 /usr/local/Library/Formula/subversion.rb
# 1.6.3    git checkout 6b6d369 /usr/local/Library/Formula/subversion.rb
# $ cd `brew --prefix`
# $ git checkout 6e2d550 /usr/local/Library/Formula/subversion.rb
# $ brew install subversion
# $ brew switch subversion 1.6.17
# $ git checkout -- Library/Formula/subversion.rb