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


当前回答

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

其他回答

意外升级Postgres?

我的案例:

postgresql意外地从11升级到12(在运行brew升级后没有参数)我想让Postgres保持11岁。

解决方案:

停止数据库:

brew services stop postgresql

安装Postgres 11:

brew install postgresql@11

启用它:

brew link postgresql@11 --force

(可选)将数据库数据目录从postgres重命名为postgres@11:

cd /usr/local/var
ls -lh
mv postgresql@11 postgresql@11-fresh-backup
mv postgres postgresql@11

启动数据库:

brew services start postgresql@11

如果有任何错误,请检查/usr/local/var/log/postgresql@11.log(注意@11)。

TLDR:brew安装postgresql@8.4.4有关更多详细信息,请参阅下面的答案。


*(我已经重新编辑了我的答案,以便为安装/使用自制软件的旧版本提供更全面的工作流程。如果您发现旧版本更好,请随时添加备注。)

让我们从最简单的案例开始:

1) 检查版本是否已安装(但未激活)

当自制程序安装一个新公式时,它会将其放在版本化的目录中,如/usr/local/Cellar/postgresql/9.3.1。然后,仅全局安装指向此文件夹的符号链接。原则上,这使得在两个已安装版本之间切换非常容易。(*)

如果您使用自制程序的时间较长,并且从未删除过旧版本(例如,使用brew cleanup),那么您的程序的某些旧版本可能仍然存在。如果您想简单地激活以前的版本,brew开关是最简单的方法。

使用brew-info-postgresql(或brew-switch-postgresql<TAB>)检查是否安装了旧版本:

$ brew info postgresql
postgresql: stable 9.3.2 (bottled)
http://www.postgresql.org/
Conflicts with: postgres-xc
/usr/local/Cellar/postgresql/9.1.5 (2755 files, 37M)
  Built from source
/usr/local/Cellar/postgresql/9.3.2 (2924 files, 39M) *
  Poured from bottle
From: https://github.com/Homebrew/homebrew/commits/master/Library/Formula/postgresql.rb
# … and some more

我们看到已经安装了一些旧版本。我们可以使用brew开关激活它:

$ brew switch postgresql 9.1.5
Cleaning /usr/local/Cellar/postgresql/9.1.5
Cleaning /usr/local/Cellar/postgresql/9.3.2
384 links created for /usr/local/Cellar/postgresql/9.1.5

让我们仔细检查激活的内容:

$ brew info postgresql
postgresql: stable 9.3.2 (bottled)
http://www.postgresql.org/
Conflicts with: postgres-xc
/usr/local/Cellar/postgresql/9.1.5 (2755 files, 37M) *
  Built from source
/usr/local/Cellar/postgresql/9.3.2 (2924 files, 39M)
  Poured from bottle
From: https://github.com/Homebrew/homebrew/commits/master/Library/Formula/postgresql.rb
# … and some more

请注意,星号*已移至新激活的版本

(*)请注意,brew开关仅在旧版本的所有依赖项仍然存在的情况下工作。在某些情况下,可能需要重建旧版本。因此,当想要在两个相距不太远的版本之间切换时,使用brew开关最有用。

2) 检查版本是否可用

特别是对于大型软件项目,很可能对某个软件的几个(可能不兼容API)主要版本有足够高的需求。截至2012年3月,Homebrew 0.9提供了一种机制:brew tap和自制版本存储库。

该版本存储库可能包含多个公式的旧版本的后端。(大多数只有大型和著名的,但当然,它们也有几个postgresql公式。)

brew search postgresql将向您显示查找位置:

$ brew search postgresql
postgresql
homebrew/versions/postgresql8    homebrew/versions/postgresql91
homebrew/versions/postgresql9    homebrew/versions/postgresql92

我们可以通过键入

$ brew install homebrew/versions/postgresql8
Cloning into '/usr/local/Library/Taps/homebrew-versions'...
remote: Counting objects: 1563, done.
remote: Compressing objects: 100% (943/943), done.
remote: Total 1563 (delta 864), reused 1272 (delta 620)
Receiving objects: 100% (1563/1563), 422.83 KiB | 339.00 KiB/s, done.
Resolving deltas: 100% (864/864), done.
Checking connectivity... done.
Tapped 125 formula
==> Downloading http://ftp.postgresql.org/pub/source/v8.4.19/postgresql-8.4.19.tar.bz2
# …

请注意,这已经自动点击自制程序/版本。(使用brew tap进行检查,使用brew untap自制程序/版本进行删除。)以下内容等效:

$ brew tap homebrew/versions
$ brew install postgresql8

只要后端口版本公式保持最新,这种方法可能是处理旧软件的最佳方法。

3) 尝试一些过去的公式

列出以下方法主要是为了完整性。两人都试图从酿造库中复活一些不死配方。由于依赖关系的改变,公式规范中的API改变,或者下载URL的改变,事情可能会发生,也可能不会发生。

由于整个公式目录是一个git存储库,因此可以使用普通的git命令安装特定版本。然而,我们需要找到一种方法,在旧版本可用的地方进行提交。

a) 历史性时代

在2011年8月至2014年10月期间,自制程序有一个brew版本命令,它会将所有可用版本与各自的SHA散列一起输出。从2014年10月起,你必须在使用之前先自制/装骨机。正如水龙头的名称所暗示的,你可能只能在万不得已的情况下这样做。

E.g.

$ brew versions postgresql
Warning: brew-versions is unsupported and may be removed soon.
Please use the homebrew-versions tap instead:
  https://github.com/Homebrew/homebrew-versions
9.3.2    git checkout 3c86d2b Library/Formula/postgresql.rb
9.3.1    git checkout a267a3e Library/Formula/postgresql.rb
9.3.0    git checkout ae59e09 Library/Formula/postgresql.rb
9.2.4    git checkout e3ac215 Library/Formula/postgresql.rb
9.2.3    git checkout c80b37c Library/Formula/postgresql.rb
9.2.2    git checkout 9076baa Library/Formula/postgresql.rb
9.2.1    git checkout 5825f62 Library/Formula/postgresql.rb
9.2.0    git checkout 2f6cbc6 Library/Formula/postgresql.rb
9.1.5    git checkout 6b8d25f Library/Formula/postgresql.rb
9.1.4    git checkout c40c7bf Library/Formula/postgresql.rb
9.1.3    git checkout 05c7954 Library/Formula/postgresql.rb
9.1.2    git checkout dfcc838 Library/Formula/postgresql.rb
9.1.1    git checkout 4ef8fb0 Library/Formula/postgresql.rb
9.0.4    git checkout 2accac4 Library/Formula/postgresql.rb
9.0.3    git checkout b782d9d Library/Formula/postgresql.rb

正如你所看到的,它建议不要使用它。Homebrew用它的内部启发式方法吐出了它能找到的所有版本,并向你展示了一种检索旧公式的方法。让我们试试看。

# First, go to the homebrew base directory
$ cd $( brew --prefix )
# Checkout some old formula
$ git checkout 6b8d25f Library/Formula/postgresql.rb
$ brew install postgresql
# … installing

现在安装了旧的postgresql版本,我们可以重新安装最新的公式,以保持存储库的清洁:

$ git checkout -- Library/Formula/postgresql.rb

brew switch是你在新旧之间转换的朋友。

b) 史前时代

对于特殊需求,我们也可以尝试自己通过自制回购进行挖掘。

$ cd Library/Taps/homebrew/homebrew-core && git log -S'8.4.4' -- Formula/postgresql.rb

gitlog-S查找文件Library/Taps/homebrew/homebrew core/Formula/postgresql.rb中添加或删除了字符串“8.4.4”的所有提交。结果得到两次提交。

commit 7dc7ccef9e1ab7d2fc351d7935c96a0e0b031552
Author: Aku Kotkavuo
Date:   Sun Sep 19 18:03:41 2010 +0300

    Update PostgreSQL to 9.0.0.

    Signed-off-by: Adam Vandenberg

commit fa992c6a82eebdc4cc36a0c0d2837f4c02f3f422
Author: David Höppner
Date:   Sun May 16 12:35:18 2010 +0200

    postgresql: update version to 8.4.4

显然,fa992c6a82eebdc4cc36a0c0d2837f4c02f3f422是我们感兴趣的提交。由于这个提交很旧,我们将尝试降级完整的自制程序安装(这样,公式API或多或少保证有效):

$ git checkout -b postgresql-8.4.4 fa992c6a82eebdc4cc36a0c0d2837f4c02f3f422
$ brew install postgresql
$ git checkout master
$ git branch -d postgresql-8.4.4

您可以跳过最后一个命令,将引用保存在git存储库中。

一个注意事项:在检查旧的提交时,您会暂时降级自制程序的安装。因此,您应该小心,因为自制程序中的某些命令可能与最新版本不同。

4) 手动编写公式

这并不太难,然后您可以将其上传到自己的存储库中。以前是自制版本,但现在已经停产。

A.)奖金:固定

如果你想保留的某个版本,比如postgresql,在你进行自然酿造更新时停止更新;brew升级程序,您可以固定公式:

$ brew pin postgresql

固定公式列在/usr/local/Library/PinnedKegs/中,一旦您希望引入最新的更改和更新,就可以再次取消固定:

$ brew unpin postgresql

对于brew的最后一个版本来说,这很容易做到。

brew tap homebrew/versions
brew install subversion17 # for svn 1.7 branch instead of last available
brew install postgresql8  # for postgresql 8 (which you ask)

自制软件/版本的问题是,必须有人在存储库中列出特定版本的软件才能使用它。此外,由于不再支持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机器,以获得最新版本,并使其继续下去。

更新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

希望有助于:)