2533

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

4

32 回答 32

2820

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


*(我已经重新编辑了我的答案,以提供更彻底的工作流程来安装/使用带有自制软件的旧软件版本。如果您发现旧版本更好,请随时添加注释。

让我们从最简单的情况开始:

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

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

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

检查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 switch

$ 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 switch只有在旧版本的所有依赖项仍然存在时才有效。在某些情况下,可能需要重建旧版本。因此,brew switch当一个人想要在两个相距不远的版本之间切换时,使用最有用。

2)检查版本是否可以作为水龙头使用

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

该版本存储库可能包含多个公式的旧版本的反向移植。(大多数只有大的和著名的,但当然他们也会有几个用于 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
# …

请注意,这已自动点击水龙头homebrew/versions。(检查brew tap,删除brew untap homebrew/versions。)以下将是等效的:

$ brew tap homebrew/versions
$ brew install postgresql8

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

3)尝试一些过去的公式

列出以下方法主要是为了完整性。两者都试图从 brew 存储库中复活一些不死公式。由于更改的依赖项、公式规范中的 API 更改或只是下载 URL 的更改,事情可能会或可能不会起作用。

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

a) 历史时期

在2011 年8 月到 2014 年 10 月之间,自制软件有一个brew versions命令,它会吐出所有可用版本及其各自的 SHA 哈希值。自 2014 年 10 月起,您必须先执行一次brew tap homebrew/boneyard才能使用它。正如水龙头的名称所暗示的那样,您可能只应将其作为最后的手段。

例如

$ 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) 史前时代

对于特殊需求,我们也可以尝试自己挖掘 homebrew repo。

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

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

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 存储库中。

注意事项:签出较旧的提交时,您会暂时降级您的自制软件安装。因此,您应该小心,因为 homebrew 中的某些命令可能与最新版本不同。

4)手动编写公式

这不是太难,然后您可以将其上传到您自己的存储库。曾经是Homebrew-Versions,但现在已停产。

A.) 奖金:固定

如果您想在执行自然过程时保留某个版本(例如 postgresql)并阻止其更新brew update; brew upgrade,您可以固定一个公式:

$ brew pin postgresql

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

$ brew unpin postgresql
于 2010-11-11T20:04:23.700 回答
818

简单的工作流程

现在 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
于 2012-03-22T23:29:44.270 回答
460

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

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 switch只是更改符号链接,因此速度非常快。请参阅外部命令下 Homebrew Wiki 上的更多文档。

于 2011-12-14T16:33:26.087 回答
258

更新: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 unlink docker
  • brew switch docker 1.3.3
  • 切换回 docker 1.4.1brew switch docker 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
于 2013-07-19T23:42:21.880 回答
141

按照@halfcube 的建议,这非常有效:

  1. 在https://github.com/Homebrew/homebrew-core/tree/master/Formula找到您要查找的库
  2. 点击它:https ://github.com/Homebrew/homebrew-core/blob/master/Formula/postgresql.rb
  3. 单击“历史”按钮查看旧提交:https ://github.com/Homebrew/homebrew-core/commits/master/Formula/postgresql.rb
  4. 点击你想要的:“postgresql: update version to 8.4.4”,https://github.com/Homebrew/homebrew-core/blob/8cf29889111b44fd797c01db3cf406b0b14e858c/Formula/postgresql.rb
  5. 点击“原始”链接:https ://raw.githubusercontent.com/Homebrew/homebrew-core/8cf29889111b44fd797c01db3cf406b0b14e858c/Formula/postgresql.rb
  6. brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/8cf29889111b44fd797c01db3cf406b0b14e858c/Formula/postgresql.rb
于 2011-10-16T22:12:42.137 回答
111

我发现了比其他复杂解决方案更好的替代解决方案。

brew install https://raw.github.com/Homebrew/homebrew-versions/master/postgresql8.rb

这将下载并安装 PostgreSQL 8.4.8


我通过开始按照搜索 repo 和 repo 中的评论的步骤找到了这个解决方案。

经过一番研究,发现有人收藏了一系列稀有的配方。


如果您正在寻找 MySQL 5.1.x,请尝试一下。

brew install https://raw.github.com/Homebrew/homebrew-versions/master/mysql51.rb
于 2011-09-19T11:55:43.783 回答
89

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

此方法导致错误:不支持从 GitHub 提交 URL 安装 mysql!brew extract 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)。


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

  1. 转到https://github.com/Homebrew/homebrew-core

  2. t键盘上的以激活文件查找器。

  3. 确定一个看起来最相关的公式,也许是:Formula/mysql.rb,将您带到一个论坛文件位置:https ://github.com/Homebrew/homebrew-core/blob/master/Formula/mysql.rb 。

  4. History通过单击位于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。

  1. 应用提交后,单击“查看”按钮查看 mysql.rb 文件的源代码。

  2. 然后单击“原始”按钮以查看原始源。

  3. 复制网址。或者,使用文件名自己构建 URLmysql.rb以标识您的公式和该公式的特定版本(由下面 URL 中的 commmit SHA 标识)。

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

  1. 安装它$ brew install [URL from step 7]

     $ brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/c77882756a832ac1d87e7396c114158e5619016c/Formula/mysql.rb
    
于 2016-02-24T05:38:48.243 回答
61
于 2018-12-13T16:18:05.817 回答
52

Solution

brew extract --version=8.4p1  openssh homebrew/cask
brew install openssh@8.4p1

The newest openssl@8.5p1 has bugs after I run brew upgrade, so I backed to the previous version successfully via the above way.

于 2021-03-03T13:53:19.013 回答
40

Official method ( judging from the response to https://github.com/Homebrew/brew/issues/6028 )

Unfortunately Homebrew still doesn’t have an obvious builtin way of installing an older version.

Luckily, for most formulas there’s a much easier way than the convoluted mess that used to be necessary. Here are the full instructions using bash as an example:

brew tap-new $USER/local-tap
# extract with a version seems to run a `git log --grep` under the hood
brew extract --version=4.4.23 bash $USER/local-tap
# Install your new version from the tap
brew install bash@4.4.23
# Note this "fails" trying to grab a bottle for the package and seems to have
# some odd doubling of the version in that output, but this isn't fatal.

This creates the formula@version in your custom tap that you can install per the above example. An important note is that you probably need to brew unlink bash if you had previously installed the default/latest version of the formula and then brew link bash@4.4.23 in order to use your specific version of Bash (or any other formula where you have latest and an older version installed).

A potential downside to this method is you can't easily switch back and forth between the versions because according to brew it is a "different formula".

If you want to be able to use brew switch $FORMULA $VERSION you should use the next method.


Scripted Method (Recommended)

This example shows installing the older bash 4.4.23, a useful example since the bash formula currently installs bash 5.

  • First install the latest version of the formula with brew install bash
  • then brew unlink bash
  • then install the older version you want per the snippets below
  • finally use brew switch bash 4.4.23 to set up the symlinks to your version

If you performed a brew upgrade after installing an older version without installing the latest first, then the latest would get installed clobbering your older version, unless you first executed brew pin bash.

The steps here AVOID pinning because it is easy to forget about and you might pin to a version that becomes insecure in the future (see Shellshock/etc). With this setup a brew upgrade shouldn't affect your version of Bash and you can always run brew switch bash to get a list of the versions available to switch to.

Copy and paste and edit the export lines from the code snippet below to update with your desired version and formula name, then copy and paste the rest as-is and it will use those variables to do the magic.

# This search syntax works with newer Homebrew
export BREW_FORMULA_SEARCH_VERSION=4.4.23 BREW_FORMULA_NAME=bash
# This will print any/all commits that match the version and formula name
git -C $(brew --repo homebrew/core) log \
--format=format:%H\ %s -F --all-match \
--grep=$BREW_FORMULA_SEARCH_VERSION --grep=$BREW_FORMULA_NAME

When you are certain the version exists in the formula, you can use the below:

# Gets only the latest Git commit SHA for the script further down
export BREW_FORMULA_VERSION_SHA=$(git -C $(brew --repo homebrew/core) log \
 --format=format:%H\ %s -F --all-match \
--grep=$BREW_FORMULA_SEARCH_VERSION --grep=$BREW_FORMULA_NAME | \
head -1 | awk '{print $1}')

Once you have exported the commit hash you want to use, you can use this to install that version of the package.

brew info $BREW_FORMULA_NAME \
| sed -n \
    -e '/^From: /s///' \
    -e 's/github.com/raw.githubusercontent.com/' \
    -e 's%blob/%%' \
    -e "s/master/$BREW_FORMULA_VERSION_SHA/p" \
| xargs brew install

Follow the directions in the formula output to put it into your PATH or set it as your default shell.

于 2019-04-19T16:02:43.290 回答
29

我只是使用 Homebrew 回到 Maven 2.2.1,因为简单brew install maven安装了 Maven 3.0.3。

首先,您必须将 maven 目录留在那里

$ brew unlink Maven

使用 brew tap 命令

$ brew tap homebrew/versions
克隆到 '/usr/local/Library/Taps/homebrew-versions'...
远程:计数对象:590,完成。
远程:压缩对象:100% (265/265),完成。
远程:总计 590(增量 362),重复使用 549(增量 325)
接收对象:100% (590/590), 117.49 KiB | 79 KiB/s,完成。
解决增量:100% (362/362),完成。
挖掘 50 公式

现在您可以安装 maven2 公式:

$ brew install maven2
==> 下载 http://www.apache.org/dist/maven/maven-2/2.2.1/binaries/apache-maven-2.2.1-bin.tar.gz
################################################# ###################### 100.0%
/usr/local/Cellar/maven2/2.2.1:10个文件,3.1M,6秒内建好
$ mvn --版本
阿帕奇 Maven 2.2.1 (r801777; 2009-08-06 12:16:01-0700)
Java版本:1.6.0_37
Java 主页:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
默认语言环境:en_US,平台编码:MacRoman
操作系统名称:“mac os x” 版本:“10.7.4” 架构:“x86_64” 系列:“mac”

编辑: 您也可以只brew switch maven 2.2.1切换到不同的版本。

编辑: Apache Maven 项目重新组织了他们的仓库。更新了此答案以解决此更改。

于 2012-02-12T20:35:23.610 回答
27

Upgraded Postgres by accident?

My case:

  • postgresql was upgraded from 11 to 12 accidentally (after running brew upgrade without arguments)
  • I want to keep Postgres 11.

Solution:

  1. Stop the DB:
brew services stop postgresql
  1. Install Postgres 11:
brew install postgresql@11
  1. Enable it:
brew link postgresql@11 --force
  1. (Optional) Rename DB data directory from postgres to postgres@11:
cd /usr/local/var
ls -lh
mv postgresql@11 postgresql@11-fresh-backup
mv postgres postgresql@11
  1. Start the DB:
brew services start postgresql@11

If you have any errors, check /usr/local/var/log/postgresql@11.log (notice the @11).

于 2020-01-10T17:07:03.063 回答
22

根据@tschundeee@Debilski 的更新 1描述的工作流程,我自动化了该过程并在此脚本中添加了清理。

下载它,把它放在你的路径和brewv <formula_name> <wanted_version>. 对于特定的 OP,它将是:

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

:)

于 2012-07-09T14:06:08.137 回答
19

Homebrew changed recently. Things that used to work do not work anymore. The easiest way I found to work (January 2021), was to:

  • Find the .rb file for my software (first go to Formulas, find the one I need and then click "History"; for CMake, this is at https://github.com/Homebrew/homebrew-core/commits/master/Formula/cmake.rb)
    • Pick the desired version among the revisions, e.g. 3.18.4, click three dots in the top right corner of the .rb file diff (...) and then click Raw. Copy the URL.
  • Unlink the old version brew unlink cmake
  • Installing directly from the git URL does not work anymore (brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/2bf16397f163187ae5ac8be41ca7af25b5b2e2cc/Formula/cmake.rb will fail)
    • Instead, download it and install from a local file curl -O https://raw.githubusercontent.com/Homebrew/homebrew-core/2bf16397f163187ae5ac8be41ca7af25b5b2e2cc/Formula/cmake.rb && brew install ./cmake.rb

Voila! You can delete the downloaded .rb file now.

于 2021-01-28T23:58:10.247 回答
18

一个更新的答案,因为这增加了@lance-pollard 已经发布的工作答案。

如何安装特定版本的公式(本例中使用的公式是terraform):

  1. 找到您的公式文件,例如:https ://github.com/Homebrew/homebrew-core/blob/master/Formula/terraform.rb
  2. 使用https://github.com/Homebrew/homebrew-core/commits/master/Formula/terraform.rb从 github 的历史记录中获取提交版本,或者git log master -- Formula/terraform.rb如果您在本地克隆了 repo。
  3. 使用公式的提交版本获取原始 git URL:如果 github.com 中的公式链接是https://github.com/Homebrew/homebrew-core/blob/e4ca4d2c41d4c1412994f9f1cb14993be5b2c59a/Formula/terraform.rb,您的原始 URL 将是:https ://raw.githubusercontent.com/Homebrew/homebrew-core/e4ca4d2c41d4c1412994f9f1cb14993be5b2c59a/Formula/terraform.rb
  4. 安装它:brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/e4ca4d2c41d4c1412994f9f1cb14993be5b2c59a/Formula/terraform.rb
于 2017-12-19T20:45:46.710 回答
12

在最新版本的自制软件(撰写本文时为 0.9.5)上,您要安装的自制软件桶版本将有一个特定的配方。例子:

$ brew search mongodb
mongodb    mongodb24  mongodb26

然后brew install mongodb26像往常一样做。

如果您已经安装了最新版本,请务必取消链接最新版本并链接所需版本:brew unlink mongodb && brew link mongodb26.

于 2015-04-30T22:01:25.037 回答
11

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

我想安装docker-machine未在homebrew/versions. 我使用下面的方法解决了这个问题,它也应该适用于任何 brew 安装的软件。下面的示例将docker-machine用作我想从版本 0.5.0 降级到 0.4.1 的包。

  1. 转到您的自制程序Formula目录。
    您可以通过运行来确定这一点brew info [any package name]。例如,brew info docker-machine给我一条显示路径的线 - /usr/local/Cellar/docker-machine/0.5.0。这告诉我,在我的机器上,自制软件安装在/usr/local并且我的Formula 目录默认位于/usr/local/Library/Formula

  2. 找到您的包的特定公式文件 (.rb)。 由于我想降级docker-machine,我可以看到一个docker-machine.rb文件。

  3. 获取此公式文件的版本历史记录。输入git log docker-machine.rb。这将列出该文件的完整提交历史记录。你会看到这样的输出:

    ...更多的

    提交 20c7abc13d2edd67c8c1d30c407bd5e31229cacc
    作者:BrewTestBot
    日期:2015 年 11 月 5 日星期四 16:14:18 +0000

        码头机器:更新 0.5.0 瓶。

    提交 8f615708184884e501bf5c16482c95eff6aea637
    作者:文森特·莱西尔斯
    日期:2015 年 10 月 27 日星期二 22:25:30 +0100

        码头机器 0.5.0

        将 docker-machine 更新为 0.5.0

        关闭#45403。

        签字人:Dominyk Tiller

    提交 5970e1af9b13dcbeffd281ae57c9ab90316ba423
    作者:BrewTestBot
    日期:2015 年 9 月 21 日星期一 14:04:04 +0100

        码头机器:更新 0.4.1 瓶。

    提交 18fcbd36d22fa0c19406d699308fafb44e4c8dcd
    作者:BrewTestBot
    日期:2015 年 8 月 16 日星期日 09:05:56 +0100

        码头机器:更新 0.4.1 瓶。

    ...更多的

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

  1. 获取以前版本的公式文件。 使用第 3 步中的提交标记(您可以使用前 6 个字符),您可以使用以下命令获取旧版本的公式文件:

    git checkout 5970e1 docker-machine.rb

  2. 卸载您当前的软件包版本。 只需运行正常的 brew 命令即可卸载当前版本的软件包。
    前任。brew uninstall docker-machine

  3. 安装较旧的软件包版本 现在,您只需运行正常的 brew install 命令,它将安装您已签出的公式。前任。brew install docker-machine

brew link docker-machine如有必要,您可能需要使用重新链接。

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

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

然后,您可以获得最新版本brew uninstall docker-machinebrew install docker-machine保持这种方式向前发展。

于 2015-11-10T17:30:15.993 回答
11

编辑:2021,由于不推荐使用 github 安装,此答案不再起作用。(感谢蒂姆史密斯的更新)。

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

在本地找到本地 homebrew git 目录或克隆 Homebrew/homebrew-core

cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/

或者

git clone git@github.com:Homebrew/homebrew-core.git

列出所有可用版本

git log master -- Formula/flyway.rb

复制你想要的版本的提交 ID 并直接安装

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/793abfa325531415184e1549836c982b39e89299/Formula/flyway.rb

于 2018-05-24T16:12:16.347 回答
10

I've tried most of the solutions here and they are outdated. I had to combine some ideas from here with my own work. As a result I've created a script to help me do the heavy lifting which you can find here

Usage:

brewv.sh formula_name desired_version
于 2019-02-20T15:38:47.273 回答
6

对于 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)
于 2014-08-11T06:26:14.167 回答
6

如果你找不到你的版本brew search <formula>,你也可以尝试查看你的公式的提交日志来找到你想要的版本:

这是通过 brew 安装旧版本 nginx 的示例:

从那里,我们可以1.6.3使用 sha 和原始 git url 进行安装:

brew install https://raw.githubusercontent.com/Homebrew/homebrew/eba75b9a1a474b9fc4df30bd0a32637fa31ec049/Library/Formula/nginx.rb

于 2015-09-15T18:32:15.340 回答
6

这些都不适用于我的案例(Python),所以我将添加我的 2 美分:

cd `brew --prefix`
git log Library/Formula/python.rb

输出如下所示:

commit 9ff2d8ca791ed1bd149fb8be063db0ed6a67a6de
Author: Dominyk Tiller <dominyktiller@gmail.com>
Date:   Thu Jun 30 17:42:18 2016 +0100

    python: clarify pour_bottle reason

commit cb3b29b824a264895434214e191d0d7ef4d51c85
Author: BrewTestBot <brew-test-bot@googlegroups.com>
Date:   Wed Jun 29 14:18:40 2016 +0100

    python: update 2.7.12 bottle.

commit 45bb1e220341894bbb7de6fd3f6df20987dc14f0
Author: Rakesh <rakkesh@users.noreply.github.com>
Date:   Wed Jun 29 10:02:26 2016 +0530

    python 2.7.12

    Closes #2452.

    Signed-off-by: Tim D. Smith <git@tim-smith.us>

commit cf5da0547cd261f79d69e7ff62fdfbd2c2d646e9
Author: BrewTestBot <brew-test-bot@googlegroups.com>
Date:   Fri Jun 17 20:14:36 2016 +0100

    python: update 2.7.11 bottle.

...

我想要版本2.7.11,所以我的哈希是cf5da0547cd261f79d69e7ff62fdfbd2c2d646e9(或cf5da05简称)。接下来,我检查该版本并安装公式python

git checkout cf5da05
brew install python

最后,清理:

git checkout master
于 2016-07-05T21:18:07.890 回答
6

Currently the old ways of installing specific formula versions have been deprecated. So it seems like we have to use brew edit [formula]. E.g. say we want to install an the 62.1 version of icu4c (needed e.g. for postgresql 10.5). Then you'd have to

> brew edit icu4c
# drops you to editor

Here you'd have to alter the url, version and sha256 (perhaps also mirror) to the corresponding 62.1 strings.

url "https://ssl.icu-project.org/files/icu4c/62.1/icu4c-62_1-src.tgz"
mirror "https://github.com/unicode-org/icu/releases/download/release-62-1/icu4c-62_1-src.tgz"
version "62.1"
sha256 "3dd9868d666350dda66a6e305eecde9d479fb70b30d5b55d78a1deffb97d5aa3"

then run brew reinstall icu4c to finally download the 62.1 version.

于 2019-01-24T05:46:14.623 回答
4

The other answers here are great, but if you need to install an older version of the package and ensure that the package name is modified, you'll need a different approach. This is important when using scripts (in my case, PHP build scripts) which use brew --prefix package_name to determine what directory to use for compilation.

If you are using brew extract a version is added to the end of the package name which will break the brew --prefix lookup.

Here's how to install an older package version while maintaining the original package name:

# 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

I wrote more about this here.

于 2021-05-11T14:24:12.827 回答
2

I created a tool to ease the process prescribed in this answer.

To find a package pkg with version a.b.c, run:

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

This will list commits on the pkg homebrew formula that mention the given version along with their GitHub urls.

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: 

Verify the commit from the given URL, and enter the index of the selected commit.

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

Copy and run the given command to install.

于 2020-05-06T08:21:03.427 回答
2

Here my simple answer for it - was really annoyed that there is no built in solution for that so I've built my own lazy "script". Feel free to contribute

# Please define variables
packageName=<packageName>
packageVersion=<packageVersion>

# Create a new tab
brew tap-new local/$packageName

# Extract into local tap
brew extract --version=$packageVersion $packageName local/$packageName

# Verify packages is present
brew search $packageName@

# Run brew install@version as usual
brew install local/$packageName/$packageName@$packageVersion

https://gist.github.com/ArgonQQ/cff4834dab6b254cc2140bb1454b47ef

于 2021-05-05T10:44:58.063 回答
1

将 Library/Formula/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 could not create shared memory segment错误,要像这样解决该更新 /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

希望有帮助:)

于 2011-07-13T16:30:50.257 回答
1

我刚刚将旧版本的 elasticsearch 复制到/usr/local/Cellar/elasticsearch目录中。

$ 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

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

于 2017-09-08T11:53:29.063 回答
1

brew versions and brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/<COMMIT-HASH>/Formula/<Formula>.rb not supported now.

You can try like this:

$ brew extract --version 5.6.2 gradle vitahlin/core
$ brew install gradle@5.6.2
于 2020-11-06T10:56:49.617 回答
1

Here is how I downgrade KOPS (which does not support versioning)

# 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
于 2021-01-25T12:10:47.577 回答
0

我决定,根据我更好的判断,为 Maven 3.1.1 创建一个公式,但它homebrew/versions没有。去做这个:

  1. homebrew/versions我在 github 上分叉了。
  2. 我符号链接$(brew --prefix)/Library/Taps到我的叉子的本地工作副本。我会打电话给这个my-homebrew/versions
  3. 我通过将公式指定为 进行测试my-homebrew/versions/<formula>
  4. homebrew/versions我向我的新公式发送了拉取请求。

耶。

于 2013-11-02T13:30:57.597 回答
0

对于当前不在默认 brew 公式中的版本,您可以使用https://github.com/buildtools-version-taps/homebrew-versions-tap-tool中的工具轻松创建自己的水龙头

于 2017-07-15T17:18:52.063 回答