Homebrew安装特定版本的公式?

发布于 2024-09-28 10:48:56 字数 56 浏览 4 评论 0 原文

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

How do I install a specific version of a formula in homebrew? For example, postgresql-8.4.4 instead of the latest 9.0.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(30

半步萧音过轻尘 2024-10-05 10:48:57

我创建了一个工具来简化这个答案

要查找版本为 abc 的包 pkg,请运行:

$ brew-install-specific [email protected]

这将列出 pkg 自制程序公式中提及给定版本及其 GitHub 的提交网址。

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: 

验证来自给定 URL 的提交,并输入所选提交的索引。

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

复制并运行给定的命令进行安装。

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 [email protected]

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.

深海夜未眠 2024-10-05 10:48:57

将 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 无法创建共享内存段 错误,要解决此问题,请像这样更新 /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

希望有帮助:)

Update on the Library/Formula/postgresql.rb line 8 to

http://ftp2.uk.postgresql.org/sites/ftp.postgresql.org/source/v8.4.6/postgresql-8.4.6.tar.bz2

And MD5 on line 9 to

fcc3daaf2292fa6bf1185ec45e512db6

Save and exit.

brew install postgres
initdb /usr/local/var/postgres

Now in this stage you might face the postgresql could not create shared memory segment error, to work around that update the /etc/sysctl.conf like this:

kern.sysv.shmall=65536
kern.sysv.shmmax=16777216

Try initdb /usr/local/var/postgres again, and it should run smooth.

To run postgresql on start

launchctl load -w /usr/local/Cellar/postgresql/8.4.6/org.postgresql.postgres.plist

Hope that helps :)

没有你我更好 2024-10-05 10:48:56

TLDR: brew install [电子邮件受保护]有关更多详细信息,请参阅下面的答案


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

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

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

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

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

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

$ 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点击 & 自制版本存储库。

该版本存储库可能包括多个公式的旧版本的向后移植。 (大多数只有大的和著名的,但当然他们也会有几个 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)尝试一些过去的公式

列出以下方法主要是为了完整性。两者都试图从酿造存储库中复活一些不死配方。由于依赖关系发生变化、公式规范中的 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) 史前时代

对于特殊需求,我们也可以尝试自己挖掘自制软件仓库。

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

git log -S 查找在文件 Library/Taps/homebrew/homebrew- 中添加或删除字符串 '8.4.4' 的所有提交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 或多或少可以保证valid):

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

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

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

4)手动编写公式

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

A.) 奖励:固定

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

$ brew pin postgresql

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

$ brew unpin postgresql

TLDR: brew install [email protected] See answer below for more details.


*(I’ve re-edited my answer to give a more thorough workflow for installing/using older software versions with homebrew. Feel free to add a note if you found the old version better.)

Let’s start with the simplest case:

1) Check, whether the version is already installed (but not activated)

When homebrew installs a new formula, it puts it in a versioned directory like /usr/local/Cellar/postgresql/9.3.1. Only symbolic links to this folder are then installed globally. In principle, this makes it pretty easy to switch between two installed versions. (*)

If you have been using homebrew for longer and never removed older versions (using, for example brew cleanup), chances are that some older version of your program may still be around. If you want to simply activate that previous version, brew switch is the easiest way to do this.

Check with brew info postgresql (or brew switch postgresql <TAB>) whether the older version is installed:

$ 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

We see that some older version is already installed. We may activate it using 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

Let’s double-check what is activated:

$ 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

Note that the star * has moved to the newly activated version

(*) Please note that brew switch only works as long as all dependencies of the older version are still around. In some cases, a rebuild of the older version may become necessary. Therefore, using brew switch is mostly useful when one wants to switch between two versions not too far apart.

2) Check, whether the version is available as a tap

Especially for larger software projects, it is very probably that there is a high enough demand for several (potentially API incompatible) major versions of a certain piece of software. As of March 2012, Homebrew 0.9 provides a mechanism for this: brew tap & the homebrew versions repository.

That versions repository may include backports of older versions for several formulae. (Mostly only the large and famous ones, but of course they’ll also have several formulae for postgresql.)

brew search postgresql will show you where to look:

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

We can simply install it by typing

$ 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
# …

Note that this has automatically tapped the homebrew/versions tap. (Check with brew tap, remove with brew untap homebrew/versions.) The following would have been equivalent:

$ brew tap homebrew/versions
$ brew install postgresql8

As long as the backported version formulae stay up-to-date, this approach is probably the best way to deal with older software.

3) Try some formula from the past

The following approaches are listed mostly for completeness. Both try to resurrect some undead formula from the brew repository. Due to changed dependencies, API changes in the formula spec or simply a change in the download URL, things may or may not work.

Since the whole formula directory is a git repository, one can install specific versions using plain git commands. However, we need to find a way to get to a commit where the old version was available.

a) historic times

Between August 2011 and October 2014, homebrew had a brew versions command, which spat out all available versions with their respective SHA hashes. As of October 2014, you have to do a brew tap homebrew/boneyard before you can use it. As the name of the tap suggests, you should probably only do this as a last resort.

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

As you can see, it advises against using it. Homebrew spits out all versions it can find with its internal heuristic and shows you a way to retrieve the old formulae. Let’s try it.

# 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

Now that the older postgresql version is installed, we can re-install the latest formula in order to keep our repository clean:

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

brew switch is your friend to change between the old and the new.

b) prehistoric times

For special needs, we may also try our own digging through the homebrew repo.

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

git log -S looks for all commits in which the string '8.4.4' was either added or removed in the file Library/Taps/homebrew/homebrew-core/Formula/postgresql.rb. We get two commits as a result.

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

Obviously, fa992c6a82eebdc4cc36a0c0d2837f4c02f3f422 is the commit we’re interested in. As this commit is pretty old, we’ll try to downgrade the complete homebrew installation (that way, the formula API is more or less guaranteed to be valid):

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

You may skip the last command to keep the reference in your git repository.

One note: When checking out the older commit, you temporarily downgrade your homebrew installation. So, you should be careful as some commands in homebrew might be different to the most recent version.

4) Manually write a formula

It’s not too hard and you may then upload it to your own repository. Used to be Homebrew-Versions, but that is now discontinued.

A.) Bonus: Pinning

If you want to keep a certain version of, say postgresql, around and stop it from being updated when you do the natural brew update; brew upgrade procedure, you can pin a formula:

$ brew pin postgresql

Pinned formulae are listed in /usr/local/Library/PinnedKegs/ and once you want to bring in the latest changes and updates, you can unpin it again:

$ brew unpin postgresql
恰似旧人归 2024-10-05 10:48:56

简单的工作流程

现在 Homebrew/versions 已被弃用,Homebrew/core 支持具有新命名格式的几个版本的公式。

要安装特定版本,例如 postgresql 9.5,您只需运行:

$ brew install [email protected]

要列出可用版本,请使用 @ 进行搜索:

$ brew search postgresql@
==> Searching local taps...
[email protected][email protected]        [email protected]        [email protected]

Simple Workflow

Now that Homebrew/versions has been deprecated, Homebrew/core supports a few versions of formulae with a new naming format.

To install a specific version, e.g. postgresql 9.5 you simply run:

$ brew install [email protected]

To list the available versions run a search with @:

$ brew search postgresql@
==> Searching local taps...
[email protected][email protected]        [email protected]        [email protected]
作妖 2024-10-05 10:48:56

⚠ 这个答案在 2020 年 12 月之后将不再有效:
brew switch 在 HomeBrew 2.7.0 中被禁用 (在 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 switch 只是更改符号链接,因此速度非常快。请参阅 Homebrew Wiki 上 外部命令 下的更多文档。

⚠ This answer won't work anymore after December 2020:
brew switch got disabled in HomeBrew 2.7.0 (deprecated in 2.6.0)


For versions of Homebrew before 2.7:

There's now a much easier way to install an older version of a formula that you'd previously installed. Simply use

brew switch [formula] [version]

For instance, I alternate regularly between Node.js 0.4.12 and 0.6.5:

brew switch node 0.4.12
brew switch node 0.6.5

Since brew switch just changes the symlinks, it's very fast. See further documentation on the Homebrew Wiki under External Commands.

素食主义者 2024-10-05 10:48:56

更新:1/15/2015

  • 查找所需软件和版本的提交历史记录。例如我需要从 docker 版本 1.4.1 切换到 1.3.3:
    https://github.com/Homebrew/homebrew-core/commits /master/Formula/docker.rb
  • 使用此按钮查看文件: 在此处输入图像描述
  • 单击 Raw按钮: 列表项
  • 复制 URL(本例中为 docker.rb url)来自地址栏
  • brew install (可能必须 <首先 code>brew unlink,例如 brew unlink docker)
  • brew switch docker 1.3.3
  • 切换回 docker 1.4.1 brew 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

Update: 1/15/2015

  • Find the commit history of the desired software and version. e.g. I need to switch from docker version 1.4.1 to 1.3.3:
    https://github.com/Homebrew/homebrew-core/commits/master/Formula/docker.rb
  • View the file with this button: enter image description here
  • Click the Raw button: List item
  • Copy the URL (docker.rb url in this example) from address bar
  • brew install <url> (may have to brew unlink first, e.g. brew unlink docker)
  • brew switch docker 1.3.3
  • Switch back to docker 1.4.1 brew switch docker 1.4.1

From this gist

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
可可 2024-10-05 10:48:56

按照@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:将版本更新到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.r b
  6. 下载.rb 文件复制到任意文件夹(在本例中:postgresql.rb
  7. 在该文件夹中:brew install postgresql.rb

Along the lines of @halfcube's suggestion, this works really well:

  1. Find the library you're looking for at
    https://github.com/Homebrew/homebrew-core/tree/master/Formula
  2. Click it: https://github.com/Homebrew/homebrew-core/blob/master/Formula/postgresql.rb
  3. Click the "history" button to look at old commits: https://github.com/Homebrew/homebrew-core/commits/master/Formula/postgresql.rb
  4. Click the one you want: "postgresql: update version to 8.4.4", https://github.com/Homebrew/homebrew-core/blob/8cf29889111b44fd797c01db3cf406b0b14e858c/Formula/postgresql.rb
  5. Click the "raw" link: https://raw.githubusercontent.com/Homebrew/homebrew-core/8cf29889111b44fd797c01db3cf406b0b14e858c/Formula/postgresql.rb
  6. Download the .rb file to any folder (in this case: postgresql.rb)
  7. In that folder: brew install postgresql.rb
够钟 2024-10-05 10:48:56

解决方案

brew extract --version=8.4p1  openssh homebrew/cask
brew install [email protected]

最新的[电子邮件受保护]运行brew升级后出现bug,所以我通过上述方式成功回退到之前的版本。

Solution

brew extract --version=8.4p1  openssh homebrew/cask
brew install [email protected]

The newest [email protected] has bugs after I run brew upgrade, so I backed to the previous version successfully via the above way.

断念 2024-10-05 10:48:56

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

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

这将下载并安装 PostgreSQL 8.4.8


我通过开始按照搜索存储库和

经过一番研究,发现有人有一套稀有配方可供酿造。


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

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

I've discovered a better alternative solution then the other complex solutions.

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

This will download and install PostgreSQL 8.4.8


I found this solution by starting to follow the steps of searching the repo and a comment in the repo .

After a little research found that someone has a collection of rare formulars to brew up with.


If your looking for MySQL 5.1.x, give this a try.

brew install https://raw.github.com/Homebrew/homebrew-versions/master/mysql51.rb
谎言 2024-10-05 10:48:56

更新:此方法已被弃用并且不再有效。

此方法会导致错误:不支持从 GitHub 提交 URL 安装 mysql! brew extract mysql 改为 GitHub 上的稳定版本。 (UsageError)

$ 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/[email protected]

$ 

$ brew install /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Formula/[email protected]
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/[email protected]
Cask '[email protected]' is unreadable: wrong constant name #<Class:0x00007f9b9498cad8>
Warning: Treating /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Formula/[email protected] as a formula.
==> Installing [email protected] 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 "[email protected]"
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. 单击历史记录按钮查看修订历史记录,该按钮位于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. 复制网址。或者,您可以使用 mysql.rb 文件名自行构建 URL,以标识您的公式以及该公式的特定版本(由下面 URL 中的 Commit SHA 标识)。

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

  1. 使用 $brew install [步骤 7 中的 URL]

    安装它

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

UPDATE: This method is deprecated and no longer works.

This method results in error: Installation of mysql from a GitHub commit URL is unsupported! brew extract mysql to a stable tap on GitHub instead. (UsageError)

$ 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)

I tried to install with the recommended command, but it doesn't work in this particular instance of MySQL 5.7.10. You may have better luck with a more recent Formula.

$ 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/[email protected]

$ 

$ brew install /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Formula/[email protected]
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/[email protected]
Cask '[email protected]' is unreadable: wrong constant name #<Class:0x00007f9b9498cad8>
Warning: Treating /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Formula/[email protected] as a formula.
==> Installing [email protected] 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 "[email protected]"
Download failed: https://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.10.tar.gz

You could modify the Formula at the path above (written in ruby) to attempt to achieve your desired result (e.g., an installation of MySQL 5.7.10 on a recent macOS version).


You can use the strategy of identifying the formula and a particular commit in the history of the formula that matches the version of the package you'd like to install.

  1. Go to https://github.com/Homebrew/homebrew-core

  2. Press t on your keyboard to activate the file finder.

  3. Identify a formula that looks most relevant, perhaps: Formula/mysql.rb, bringing you to a forumla file location: https://github.com/Homebrew/homebrew-core/blob/master/Formula/mysql.rb.

  4. Look at the revision history by clicking on the History button, which is located at https://github.com/Homebrew/homebrew-core/commits/master/Formula/mysql.rb. If you're interested in MySQL 5.7.10, you might want to click the latest revision prior to 5.7.11, which navigates to a GitHub commit:

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

NOTE: You may have to view the commit history in your console per GitHub's suggestion if the commit history does not load in your browser. Replace the commit SHA above in the URL if you're interested in seeing that commit on GitHub. Alternatively, skip to step 7, below.

  1. Click the "View" button to view the source for the mysql.rb file after the commit was applied.

  2. Then click the "Raw" button to view the raw source.

  3. Copy the URL. Alternatively, build the URL yourself with the mysql.rb file name to identify your formula and the particular version of that formula (identified by the commmit SHA in the URL below).

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

  1. Install it with $ brew install [URL from step 7]

     $ brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/c77882756a832ac1d87e7396c114158e5619016c/Formula/mysql.rb
    
旧街凉风 2024-10-05 10:48:56

大多数其他答案现在已经过时了。不幸的是,Homebrew 仍然没有安装过时版本的内置方法,除非该版本作为单独的公式存在(例如 python@2[电子邮件受保护] ...)。

幸运的是,对于其他公式来说,有一种比过去必要的复杂混乱更简单的方法。以下是完整说明:

  1. 在日志中搜索正确的版本:

    酿造日志公式
    # 使用 j/k 或箭头键向下/向上滚动
    # 或使用例如。 /4\.4\.23 搜索特定版本
    
    # 此语法仅适用于 2.0 之前的 Homebrew 版本
    brew log --format=格式:%H\ %s -F --grep=<版本><公式>
    

    这将显示提交哈希列表。选择一个合适的版本(大多数情况下它应该非常明显,并且通常是最新的(即顶部)版本。

  2. 在上游存储库中查找公式所在的 URL:

    酿造信息<配方> | grep ^来自:
    
  3. 修复 URL:

    1. github.com 替换为 raw.githubusercontent.com
    2. blob/master 替换为我们在第一步中找到的提交哈希。
  4. 通过用提交哈希替换先前找到的 URL 中的 master 来安装所需的版本,例如:

    brew 安装 https://raw.githubusercontent.com/Homebrew/homebrew-core//Formula/.rb
    

最后一步可能需要运行 brew unlink < /code> 之前。)


如果您复制了要使用的提交哈希,您可以使用类似此示例的内容来安装该版本,将值和 bash 替换为您的提交哈希和所需的公式。

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

此示例安装的是 bash 4.4.23 而不是 bash 5,但如果您随后执行了 brew 升级,则 bash 5 将安装在顶部,除非您首先执行 brew pin bash >。为了使这个过程更顺畅而不需要固定,您应该首先使用 brew install bash 安装最新版本,然后使用 brew unlink bash 安装,然后根据上面的脚本安装您想要的旧版本,然后使用 brew switch bash 4.4.23 设置旧版本的符号链接。现在,brew 升级 不应影响您的 Bash 版本。您可以 brew switch bash 获取可切换到的版本列表。


使用仅限本地的自定义 Tap 的替代方案

实现相同目标的另一种方法似乎是:

brew tap-new username/repo-name
# extract with a version seems to run a grep under the hood
brew extract --version='4.4.23' bash username/repo-name
brew install [email protected]
# Note this "fails" when 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.

这会在您的自定义 Tap 中创建一个 formula@version,您可以根据上面的示例进行安装。缺点是您可能仍然需要 brew unlink bash 然后 brew link [电子邮件受保护] 以便使用您的特定版本的 Bash 或任何其他公式。

Most of the other answers are obsolete by now. Unfortunately Homebrew still doesn’t have a builtin way of installing an outdated version, unless that version exists as a separate formula (e.g. python@2, [email protected] …).

Luckily, for other formulas there’s a much easier way than the convoluted mess that used to be necessary. Here are the full instructions:

  1. Search for the correct version in the logs:

    brew log formula
    # Scroll down/up with j/k or the arrow keys
    # or use eg. /4\.4\.23 to search a specific version
    
    # This syntax only works on pre-2.0 Homebrew versions
    brew log --format=format:%H\ %s -F --grep=‹version› ‹formula›
    

    This will show a list of commit hashes. Take one that is appropriate (mostly it should be pretty obvious, and usually is the most recent (i.e. top) one.

  2. Find the URL at which the formula resides in the upstream repository:

    brew info ‹formula› | grep ^From:
    
  3. Fix the URL:

    1. Replace github.com with raw.githubusercontent.com
    2. Replace blob/master with the commit hash we found in the first step.
  4. Install the desired version by replacing master in the previously found URL by the commit hash, e.g.:

    brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/‹hash›/Formula/‹formula›.rb
    

(The last step may necessitate running brew unlink ‹formula› before.)


If you have copied a commit hash you want to use, you can use something like this example to install that version, replacing the value and bash with your commit hash and your desired formula.

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

This example is installing bash 4.4.23 instead of bash 5, though if you performed a brew upgrade afterward then bash 5 would get installed over top, unless you first executed brew pin bash. Instead to make this smoother WITHOUT pinning, you should first install the latest with brew install bash, then brew unlink bash, then install the older version you want per the script above, and then use brew switch bash 4.4.23 to set up the symlinks to the older version. Now a brew upgrade shouldn't affect your version of Bash. You can brew switch bash to get a list of the versions available to switch to.


Alternative using a custom local-only tap

Another way of achieving the same goal appears to be:

brew tap-new username/repo-name
# extract with a version seems to run a grep under the hood
brew extract --version='4.4.23' bash username/repo-name
brew install [email protected]
# Note this "fails" when 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 a formula@version in your custom tap that you can install per the above example. The downside is that you probably still need to brew unlink bash and then brew link [email protected] in order to use your specific version of Bash or any other formula.

生来就爱笑 2024-10-05 10:48:56

官方方法(从对 https://github.com/Homebrew/brew/issues/6028 的回复来看

不幸的是,Homebrew 仍然没有明显安装旧版本的内置方法。

幸运的是,对于大多数公式来说,有一种比过去必要的复杂混乱更简单的方法。以下是以 bash 为例的完整说明:

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 [email protected]
# 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.

这会在您的自定义 Tap 中创建 formula@version,您可以根据上面的示例进行安装。一个重要的注意事项是,如果您之前安装了公式的默认/最新版本,则可能需要 brew unlink bash,然后 brew link [email protected] 以便使用您的特定版本的 Bash(或您拥有最新和最新版本的任何其他公式)安装了旧版本)。

此方法的一个潜在缺点是您无法轻松地在版本之间来回切换,因为根据 brew 它是“不同的公式”。

如果您希望能够使用brew switch $FORMULA $VERSION,您应该使用下一个方法。


脚本方法(推荐)

此示例显示安装旧版 bash 4.4.23,这是一个有用的示例,因为 bash 公式当前安装 bash 5。

  • 首先使用 brew install bash 安装最新版本的公式
  • 然后 brew unlink bash
  • 然后根据下面的代码片段安装您想要的旧版本
  • 最后使用 brew switch bash 4.4.23 设置您的版本的符号链接

如果如果您在安装旧版本后执行了 brew 升级,而没有先安装最新版本,则安装的最新版本会破坏您的旧版本,除非您首先执行 brew pin bash

这里的步骤避免固定,因为它很容易忘记,并且您可能会固定到将来变得不安全的版本(请参阅 Shellshock/等)。通过此设置,brew 升级 不会影响您的 Bash 版本,并且您始终可以运行 brew switch bash 来获取可切换到的版本列表。

复制并粘贴并编辑下面代码片段中的 export 行,以使用所需的版本和公式名称进行更新,然后按原样复制并粘贴其余部分,它将使用这些变量来发挥作用。

# 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

当您确定公式中存在该版本时,您可以使用以下命令:

# 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}')

导出要使用的提交哈希后,您可以使用它来安装该版本的包。

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

按照公式输出中的说明将其放入您的 PATH 或将其设置为默认 shell。

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 [email protected]
# 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 [email protected] 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.

感性不性感 2024-10-05 10:48:56

Homebrew 最近发生了变化。以前有用的东西现在不再有用了。我发现最简单的工作方法(2021 年 1 月)是:

  • 找到我的软件的 .rb 文件(首先转到 Formulas,找到我需要的,然后单击“历史记录”;对于 CMake,位于 Formulas。 com/Homebrew/homebrew-core/commits/master/Formula/cmake.rb" rel="noreferrer">https://github.com/Homebrew/homebrew-core/commits/master/Formula/cmake.rb)
  • 取消链接旧版本 brew unlink cmake
  • 直接从 git URL 安装不再起作用(brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/2bf16397f163187ae5ac8be41ca7af25b5b2e2cc/Formula/ cmake.rb 将失败)
    • 而是下载并从本地文件安装 curl -O https://raw.githubusercontent.com/Homebrew/homebrew-core/2bf16397f163187ae5ac8be41ca7af25b5b2e2cc/Formula/cmake.rb &&酿造安装./cmake.rb

瞧!您现在可以删除下载的 .rb 文件。

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.

风流物 2024-10-05 10:48:56

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

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

$ brew unlink maven

使用brew tap 命令

$ brew tap homebrew/versions
Cloning into '/usr/local/Library/Taps/homebrew-versions'...
remote: Counting objects: 590, done.
remote: Compressing objects: 100% (265/265), done.
remote: Total 590 (delta 362), reused 549 (delta 325)
Receiving objects: 100% (590/590), 117.49 KiB | 79 KiB/s, done.
Resolving deltas: 100% (362/362), done.
Tapped 50 formula

现在您可以安装maven2 公式:

$ brew install maven2
==> Downloading 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 files, 3.1M, built in 6 seconds
$ mvn --version
Apache Maven 2.2.1 (r801777; 2009-08-06 12:16:01-0700)
Java version: 1.6.0_37
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x" version: "10.7.4" arch: "x86_64" Family: "mac" 

编辑:
您也可以通过 brew switch maven 2.2.1 切换到其他版本。

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

I just used Homebrew to go back to Maven 2.2.1 since the simple brew install maven installed Maven 3.0.3.

First you have to leave the maven dir there so

$ brew unlink maven

Use the brew tap command

$ brew tap homebrew/versions
Cloning into '/usr/local/Library/Taps/homebrew-versions'...
remote: Counting objects: 590, done.
remote: Compressing objects: 100% (265/265), done.
remote: Total 590 (delta 362), reused 549 (delta 325)
Receiving objects: 100% (590/590), 117.49 KiB | 79 KiB/s, done.
Resolving deltas: 100% (362/362), done.
Tapped 50 formula

Now you can install the maven2 formula:

$ brew install maven2
==> Downloading 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 files, 3.1M, built in 6 seconds
$ mvn --version
Apache Maven 2.2.1 (r801777; 2009-08-06 12:16:01-0700)
Java version: 1.6.0_37
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x" version: "10.7.4" arch: "x86_64" Family: "mac" 

Edit:
You can also just brew switch maven 2.2.1 to switch to a different version.

Edit:
The Apache Maven project reorganized their repo. Updated this answer to account for this change.

你怎么这么可爱啊 2024-10-05 10:48:56

意外升级 Postgres?

我的情况:

  • postgresql 意外地从 11 升级到 12(在不带参数运行 brew Upgrade 后)
  • 我想保留 Postgres 11。

解决方案:

  1. 停止数据库:
brew services stop postgresql
  1. 安装 Postgres 11:
brew install postgresql@11
  1. 启用它:(
brew link postgresql@11 --force
  1. 可选)将数据库数据目录从 postgres 重命名为 postgres@11
cd /usr/local/var
ls -lh
mv postgresql@11 postgresql@11-fresh-backup
mv postgres postgresql@11
  1. 启动数据库:
brew services start postgresql@11

如果有任何错误,请检查 /usr/local/ var/log/[电子邮件受保护](注意 @ 11)。

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/[email protected] (notice the @11).

风蛊 2024-10-05 10:48:56

基于 @tshundeee@Debilski 的更新 1,我自动化了该过程并在 此脚本

下载,将其放入您的路径中,然后 brewv ; 。对于特定的OP,它将是:

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

:)

Based on the workflow described by @tschundeee and @Debilski’s update 1, I automated the procedure and added cleanup in this script.

Download it, put it in your path and brewv <formula_name> <wanted_version>. For the specific OP, it would be:

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

:)

许仙没带伞 2024-10-05 10:48:56

其他答案都没有充分涵盖 2022 年的这一点,因此我添加了这些说明,这些说明改编自 Homebrew 维护者对安装特定 Cask 版本的类似问题的答案:https://stackoverflow.com/a/62765875/6310633

卸载公式

brew uninstall <formula>

切换到 homebrew-core 存储库的克隆并重置为提交包含您想要的版本。

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

当您准备好升级配方时,您可以照常brew unpin 并升级。

None of the other answers cover this adequately for 2022, so I'm adding these instructions that are adapted from a Homebrew maintainer's answer for a similar question for installing a specific Cask version: https://stackoverflow.com/a/62765875/6310633

Uninstall your formula

brew uninstall <formula>

Switch over to your clone of the homebrew-core repo and reset to a commit containing the version you want.

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>

Checkout a new branch for your version so brew won't autorefresh master after each command, install your formula, and pin it.

git checkout -b <formula>-downgrade-<version>
brew install <formula>
brew pin <formula>

Clean up

git checkout master
brew update

When you're ready to upgrade your formula, you can brew unpin <formula> and upgrade as usual.

清风疏影 2024-10-05 10:48:56

更新后的答案添加到了@lance-pollard 已经发布的工作答案中。

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

  1. 找到您的公式文件,例如:https://github.com/Homebrew/homebrew-core/blob/master/Formula/terraform.rb
  2. 从 github 获取提交版本https://github.com/Homebrew/homebrew-core 的历史/commits/master/Formula/terraform.rbgit log master -- Formula/terraform.rb 如果您已在本地克隆存储库。
  3. 获取包含公式提交版本的原始 git URL:如果 github.com 中的公式链接为 https://github.com/Homebrew/homebrew-core/blob/e4ca4d2c41d4c1412994f9f1cb14993be5b2c59a/Formula/terraform.rb,您的原始网址将为:https://raw.githubusercontent.com/Homebrew/homebrew-core/e4ca4d2c41d4c1412994f9f1cb1499 3be5b2c59a/公式/terraform.rb< /a>
  4. 安装它: brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/e4ca4d2c41d4c1412994f9f1cb14993be5b2c59a/Formula/terraform.rb

An updated answer since that adds to what @lance-pollard already posted as working answer.

How to Install specific version of a Formula (formula used in this example is terraform):

  1. Find your formula file, e.g: https://github.com/Homebrew/homebrew-core/blob/master/Formula/terraform.rb
  2. Get the commit version from github’s history with https://github.com/Homebrew/homebrew-core/commits/master/Formula/terraform.rb or git log master -- Formula/terraform.rb if you have cloned the repo locally.
  3. Get the raw git URL with the commit version of your formula: If the formula link in github.com is https://github.com/Homebrew/homebrew-core/blob/e4ca4d2c41d4c1412994f9f1cb14993be5b2c59a/Formula/terraform.rb, your raw URL will be: https://raw.githubusercontent.com/Homebrew/homebrew-core/e4ca4d2c41d4c1412994f9f1cb14993be5b2c59a/Formula/terraform.rb
  4. Install it with: brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/e4ca4d2c41d4c1412994f9f1cb14993be5b2c59a/Formula/terraform.rb
美人如玉 2024-10-05 10:48:56

这里的其他答案都很好,但是如果您需要安装旧版本的软件包并确保修改软件包名称,则需要采用不同的方法。当使用使用 brew --prefix package_name 来确定用于编译的目录的脚本(在我的例子中为 PHP 构建脚本)时,这一点很重要。

如果您使用 brew extract ,则会在包名称末尾添加一个版本,这将破坏 brew --prefix 查找。

以下是如何安装较旧的软件包版本,同时保留原始软件包名称:

# 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 [email protected] 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

我写了更多关于此的内容在这里。

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 [email protected] 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.

这样的小城市 2024-10-05 10:48:56

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

$ brew search mongodb
mongodb    mongodb24  mongodb26

然后像平常一样执行 brew install mongodb26

如果您已经安装了最新版本,请确保取消链接最新版本并链接所需版本: brew unlink mongodb &&酿造链接mongodb26

On the newest version of homebrew (0.9.5 as of this writing) there will be a specific recipe for the version of the homebrew keg you want to install. Example:

$ brew search mongodb
mongodb    mongodb24  mongodb26

Then just do brew install mongodb26 like normal.

In the case that you had already installed the latest version, make sure to unlink the latest version and link the desired version: brew unlink mongodb && brew link mongodb26.

青柠芒果 2024-10-05 10:48:56

homebrew/versions 的问题在于,某人必须拥有存储库中列出的特定版本的软件,您才能使用它。此外,由于不再支持 brew versions,因此需要另一种解决方案。对于指示使用 brew switch 的解决方案,只有在您尚未执行 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。这将列出该文件的完整提交历史记录。您将看到如下输出:

    ...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 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 重新链接。

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

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

然后您可以 brew uninstall docker-machinebrew install docker-machine 来获取最新版本并保持这种状态。

The problem with homebrew/versions is that someone has to have that specific version of software listed in the repository for you to be able to use it. Also, since brew versions is no longer supported, another solution is required. For solutions that indicate using brew switch, this will only work if you haven't done a brew cleanup since the version needs to exist on your computer.

I had a problem with wanting to install a specific older version of docker-machine which wasn't listed in homebrew/versions. I solved this using the below, which should also work for any brew installed software. The example below will use docker-machine as the package I want to downgrade from version 0.5.0 to 0.4.1.

  1. Go to your homebrew Formula directory.
    You can determine this by running brew info [any package name].
    For example, brew info docker-machine gives me a line that shows me
    a path - /usr/local/Cellar/docker-machine/0.5.0. This tells me that on my machine, homebrew is installed at /usr/localand my Formula
    directory is located by default at /usr/local/Library/Formula

  2. Locate the specific formula file (.rb) for your package.
    Since I want to downgrade docker-machine, I can see a docker-machine.rb file.

  3. Get the version history for this formula file .
    Enter git log docker-machine.rb. This will list out the complete commit history for this file. You will see output like this:

    ...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

The tricky part is to find the latest commit for the specific version you want. In the above, I can tell the latest 0.4.1 version was committed with this commit tag : commit 5970e1af9b13dcbeffd281ae57c9ab90316ba423. The commits above this point start using version 0.5.0 (git log entries are listed from latest to earliest date).

  1. Get a previous version of the formula file.
    Using the commit tag from step #3 (you can use the first 6 chars), you can get an older version of the formula file using the following:

    git checkout 5970e1 docker-machine.rb

  2. Uninstall your current package version.
    Just run the normal brew commands to uninstall the current version of your package.
    Ex. brew uninstall docker-machine

  3. Install the older package version
    Now, you can just run the normal brew install command and it will install the formula that you have checkout out.
    Ex. brew install docker-machine

You may need to re-link by using the brew link docker-machine if necessary.

If at any time you want to revert back to the latest version of a specific package, go into the Formula directory and issue the following commands on your formula file (.rb)

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

Then you can brew uninstall docker-machine and brew install docker-machine to get the latest version and keep it that way going forward.

美人迟暮 2024-10-05 10:48:56

编辑:2021 年,由于 github 安装已被弃用,此答案不再起作用。(感谢 Tim Smith 的更新)。

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

查找本地自制程序git目录或在本地克隆Homebrew/homebrew-core

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

git clone [email protected]:Homebrew/homebrew-core.git

列出所有可用版本

git log master -- Formula/flyway.rb

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

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

Edit: 2021, this answer is no longer functional due to the github install being deprecated. (Thanks Tim Smith for update).

Install an old brew package version (Flyway 4.2.0 example)

Find your local homebrew git dir or clone Homebrew/homebrew-core locally

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

OR

git clone [email protected]:Homebrew/homebrew-core.git

List all available versions

git log master -- Formula/flyway.rb

Copy the commit ID for the version you want and install it directly

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/793abfa325531415184e1549836c982b39e89299/Formula/flyway.rb
_畞蕅 2024-10-05 10:48:56

我已经尝试了这里的大多数解决方案,但它们已经过时了。我必须将这里的一些想法与我自己的工作结合起来。因此,我创建了一个脚本来帮助我完成繁重的工作,您可以在此处找到该脚本

用法:

brewv.sh formula_name desired_version

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
冰魂雪魄 2024-10-05 10:48:56

目前安装特定公式版本的旧方法已被弃用。所以看来我们必须使用 brew edit [formula]。例如,假设我们要安装 62.1 版本的 icu4c(例如 postgresql 10.5 需要)。然后你必须在

> brew edit icu4c
# drops you to editor

这里你必须改变urlversionsha256(也许还有mirror) 到相应的 62.1 字符串。

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"

然后运行 ​​brew reinstall icu4c 最终下载 62.1 版本。

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.

千里故人稀 2024-10-05 10:48:56

在这里,我对此的简单回答 - 真的很恼火,因为没有内置的解决方案,所以我构建了自己的懒惰“脚本”。欢迎贡献

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

你列表最软的妹 2024-10-05 10:48:56

对于最新版本的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)

it could be done very easy for last version of 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)
别念他 2024-10-05 10:48:56

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

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

输出如下所示:

<前><代码>提交 9ff2d8ca791ed1bd149fb8be063db0ed6a67a6de
作者:Dominyk Tiller <[电子邮件受保护]>
日期: 2016 年 6 月 30 日星期四 17:42:18 +0100

python:澄清 pour_bottle 原因

提交 cb3b29b824a264895434214e191d0d7ef4d51c85
Author: BrewTestBot <[email protected]>
日期:2016 年 6 月 29 日星期三 14:18:40 +0100

python:更新2.7.12瓶子。

提交 45bb1e220341894bbb7de6fd3f6df20987dc14f0
作者:Rakesh [电子邮件受保护] >
日期:2016 年 6 月 29 日星期三 10:02:26 +0530

蟒蛇2.7.12

关闭#2452。

签署人:Tim D. Smith [电子邮件受保护] >

提交 cf5da0547cd261f79d69e7ff62fdfbd2c2d646e9
作者:BrewTestBot [电子邮件受保护]>
日期:2016 年 6 月 17 日星期五 20:14:36 +0100

python:更新2.7.11瓶子。

...

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

git checkout cf5da05
brew install python

最后,清理:

git checkout master

None of these really worked for my case (Python), so I'll add my 2 cents:

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

Output looks like this:

commit 9ff2d8ca791ed1bd149fb8be063db0ed6a67a6de
Author: Dominyk Tiller <[email protected]>
Date:   Thu Jun 30 17:42:18 2016 +0100

    python: clarify pour_bottle reason

commit cb3b29b824a264895434214e191d0d7ef4d51c85
Author: BrewTestBot <[email protected]>
Date:   Wed Jun 29 14:18:40 2016 +0100

    python: update 2.7.12 bottle.

commit 45bb1e220341894bbb7de6fd3f6df20987dc14f0
Author: Rakesh <[email protected]>
Date:   Wed Jun 29 10:02:26 2016 +0530

    python 2.7.12

    Closes #2452.

    Signed-off-by: Tim D. Smith <[email protected]>

commit cf5da0547cd261f79d69e7ff62fdfbd2c2d646e9
Author: BrewTestBot <[email protected]>
Date:   Fri Jun 17 20:14:36 2016 +0100

    python: update 2.7.11 bottle.

...

I want version 2.7.11 so my hash is cf5da0547cd261f79d69e7ff62fdfbd2c2d646e9 (or cf5da05 for short). Next, I check out that version and install the formula python:

git checkout cf5da05
brew install python

Finally, clean up:

git checkout master
紅太極 2024-10-05 10:48:56

如果您无法使用 brew search 找到您的版本,您还可以尝试查看公式的提交日志来查找您想要的版本:

以下是安装旧版本的示例通过brew获取的nginx版本:

从那里,我们可以安装1.6 .3 使用 sha 和原始 git url:

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

If you can't find your version with brew search <formula>, you can also try going over the commit logs for your formula to find the version you want:

here is an example for installing an older version of nginx via brew:

From there, we can install 1.6.3 with the sha and raw git url:

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

夏の忆 2024-10-05 10:48:56

当我尝试使用所有其他方法时,它们不再起作用,因为 Homebrew 似乎继续对他们自己的工具发动战争。

因此,我制作了一个 brew-switch 函数,您可以将其添加到 ~/.zshrc 中,该函数将下载任何核心公式的任何版本(请参阅 Homebrew GitHub 上的讨论)。

它的工作原理是:

  1. Homebrew/homebrew-core 中搜索提交包含公式名称和请求版本的最新存储库,
  2. 从该提交下载 .rb 文件
  3. 使用 brew install ./.rb 来安装文件,
  4. 在本地运行 brew pin

以阻止 brew Upgrade 弄乱它用法

一般用法是:

brew-switch <formula> <version>

例如,安装版本argocd公式的2.8.6

brew-switch argocd 2.8.6

安装

1.依赖

# install github command line
brew install gh

# authenticate with your github account
gh auth login

2.在.zshrc中添加brew-switch

打开您的 ~/.zshrc 文件,并添加 brew-switch 函数。

例如,如果您喜欢 vim

## don't forget to close and reopen your terminal after changing
vim ~/.zshrc

将这些行添加到文件末尾:

# a script to install a specific version of a formula from homebrew-core
# USAGE: brew-switch <formula> <version>
function brew-switch {
  local _formula=$1
  local _version=$2

  # fail for missing arguments
  if [[ -z "$_formula" || -z "$_version" ]]; then
    echo "USAGE: brew-switch <formula> <version>"
    return 1
  fi

  # ensure 'gh' is installed
  if [[ -z "$(command -v gh)" ]]; then
    echo ">>> ERROR: 'gh' must be installed to run this script"
    return 1
  fi

  # find the newest commit for the given formula and version
  local _commit_sha=$(
    gh search commits \
      --owner Homebrew \
      --repo homebrew-core \
      --limit 1 \
      --sort committer-date \
      --order desc \
      --json sha \
      --jq '.[0].sha' \
      "\"${_formula}\" \"${_version}\""
  )

  # fail if no commit was found
  if [[ -z "$_commit_sha" ]]; then
    echo "ERROR: No commit found for ${_formula}@${_version}"
    return 1
  else
    echo "INFO: Found commit ${_commit_sha} for ${_formula}@${_version}"
  fi

  # download the formula file from the commit
  local _raw_url="https://raw.githubusercontent.com/Homebrew/homebrew-core/${_commit_sha}/Formula/${_formula:0:1}/${_formula}.rb"
  local _formula_path="/tmp/${_formula}.rb"
  echo "INFO: Downloading ${_raw_url}"
  if ! curl -fL "$_raw_url" -o "$_formula_path"; then
    echo ""
    echo "WARNING: Download failed, trying old formula path"

    # try the old formula path
    _raw_url="https://raw.githubusercontent.com/Homebrew/homebrew-core/${_commit_sha}/Formula/${_formula}.rb"
    echo "INFO: Downloading ${_raw_url}"
    curl -fL "$_raw_url" -o "$_formula_path" || (echo "ERROR: Failed to download ${_raw_url}" && return 1)
  fi

  # if the formula is already installed, uninstall it
  if brew ls --versions "$_formula" >/dev/null; then
    echo ""
    echo "WARNING: '$_formula' already installed, do you want to uninstall it? [y/N]"
    local _reply=$(bash -c "read -n 1 -r && echo \$REPLY")
    echo ""
    if [[ $_reply =~ ^[Yy]$ ]]; then
      echo "INFO: Uninstalling '$_formula'"
      brew unpin "$_formula"
      brew uninstall "$_formula" || (echo "ERROR: Failed to uninstall '$_formula'" && return 1)
    else
      echo "ERROR: '$_formula' is already installed, aborting"
      return 1
    fi
  fi

  # install the downloaded formula
  echo "INFO: Installing ${_formula}@${_version} from local file: $_formula_path"
  brew install --formula "$_formula_path"
  brew pin "$_formula"
}

When I tried to use all the other methods, they were no longer working, as it seems Homebrew continues to wage a war against their own tool.

So I have made a brew-switch function that you can add to your ~/.zshrc that will download any version of any core formula (see the discussion on the Homebrew GitHub).

It works by:

  1. searching commits in the Homebrew/homebrew-core repo for the most recent one that contains the name of your formula and the requested version
  2. downloading the <formula>.rb file from that commit
  3. using brew install ./<formula>.rb to install the file locally
  4. running brew pin <formula> to stop brew upgrade from messing with it

Usage

The general usage is:

brew-switch <formula> <version>

For example, to install version 2.8.6 of the argocd formula:

brew-switch argocd 2.8.6

Install

1. Dependencies

# install github command line
brew install gh

# authenticate with your github account
gh auth login

2. Add brew-switch to .zshrc

Open your ~/.zshrc file, and add the brew-switch function.

For example, if you like vim:

## don't forget to close and reopen your terminal after changing
vim ~/.zshrc

Add these lines to the end of the file:

# a script to install a specific version of a formula from homebrew-core
# USAGE: brew-switch <formula> <version>
function brew-switch {
  local _formula=$1
  local _version=$2

  # fail for missing arguments
  if [[ -z "$_formula" || -z "$_version" ]]; then
    echo "USAGE: brew-switch <formula> <version>"
    return 1
  fi

  # ensure 'gh' is installed
  if [[ -z "$(command -v gh)" ]]; then
    echo ">>> ERROR: 'gh' must be installed to run this script"
    return 1
  fi

  # find the newest commit for the given formula and version
  local _commit_sha=$(
    gh search commits \
      --owner Homebrew \
      --repo homebrew-core \
      --limit 1 \
      --sort committer-date \
      --order desc \
      --json sha \
      --jq '.[0].sha' \
      "\"${_formula}\" \"${_version}\""
  )

  # fail if no commit was found
  if [[ -z "$_commit_sha" ]]; then
    echo "ERROR: No commit found for ${_formula}@${_version}"
    return 1
  else
    echo "INFO: Found commit ${_commit_sha} for ${_formula}@${_version}"
  fi

  # download the formula file from the commit
  local _raw_url="https://raw.githubusercontent.com/Homebrew/homebrew-core/${_commit_sha}/Formula/${_formula:0:1}/${_formula}.rb"
  local _formula_path="/tmp/${_formula}.rb"
  echo "INFO: Downloading ${_raw_url}"
  if ! curl -fL "$_raw_url" -o "$_formula_path"; then
    echo ""
    echo "WARNING: Download failed, trying old formula path"

    # try the old formula path
    _raw_url="https://raw.githubusercontent.com/Homebrew/homebrew-core/${_commit_sha}/Formula/${_formula}.rb"
    echo "INFO: Downloading ${_raw_url}"
    curl -fL "$_raw_url" -o "$_formula_path" || (echo "ERROR: Failed to download ${_raw_url}" && return 1)
  fi

  # if the formula is already installed, uninstall it
  if brew ls --versions "$_formula" >/dev/null; then
    echo ""
    echo "WARNING: '$_formula' already installed, do you want to uninstall it? [y/N]"
    local _reply=$(bash -c "read -n 1 -r && echo \$REPLY")
    echo ""
    if [[ $_reply =~ ^[Yy]$ ]]; then
      echo "INFO: Uninstalling '$_formula'"
      brew unpin "$_formula"
      brew uninstall "$_formula" || (echo "ERROR: Failed to uninstall '$_formula'" && return 1)
    else
      echo "ERROR: '$_formula' is already installed, aborting"
      return 1
    fi
  fi

  # install the downloaded formula
  echo "INFO: Installing ${_formula}@${_version} from local file: $_formula_path"
  brew install --formula "$_formula_path"
  brew pin "$_formula"
}
你又不是我 2024-10-05 10:48:56

最接近@Lance的答案,但这对我来说不起作用,在2023年,使用M1 macOS 13并试图安装特定版本的opencv@4

底线是:您应该使用在brew中找到的远程opencv.rb文件的内容覆盖本地opencv.rb文件的内容GitHub 存储库,与您要安装的 opencv 版本相对应。

本质上,我们想要更新包的 .rb 文件中的 urlsha256。但 sha256 无法从 opencv Releases Github 获取 页面并在本地创建 sha256 会给我抛出一个 checksum 错误。但是从提交历史记录的 .rb 文件中获取它们可以解决此问题。

分解:只需 5 个简单步骤

  1. 首先卸载软件包:brew uninstall opencv@4

  2. 找到您要安装的软件包的正确版本的.rb文件

    1. 在 Homebrew 下搜索 >自制核心> Github

      上的公式

    2. opencv.rb文件的历史中:https://github.com/Homebrew/homebrew-core/commits/master/Formula/opencv.rb

      • 选择与所需版本对应的提交,例如 opencv: update 4.6.0_1 Bottle。 并查看文件。
      • 复制内容/下载文件
  3. 打开系统上的.rb文件:brew edit opencv@4

  4. 将此文件的内容替换为您从 Github 下载的文件

  5. 使用 .rb 文件路径再次安装软件包:brew install /opt/homebrew/Library/Taps/homebrew/ homebrew-core/Formula/opencv.rb

效果很好对我来说,@Lance 使用 brew install 的答案给出了 Error: Your Command Line Tools (CLT) does not support macOS 13.

其他答案都不适合我任何一个。

Closest to @Lance's answer but that didn't work for me as is, in 2023, using M1 macOS 13 and trying to install specific version of opencv@4.

Bottom-line is: you should override the content of your local opencv.rb file with that of the remote opencv.rb file found in brew's GitHub repo, that corresponds to the version of opencv you want to install.

Essentially, we want to update the url and sha256 in the .rb file for the package. But sha256 were not available from the opencv Releases Github page and creating sha256 locally throws a checksum error for me. But getting them from the .rb file from the commit history resolves this issue.

Breakdown: in 5 simple steps

  1. Uninstall the package first: brew uninstall opencv@4

  2. Find the .rb file for the correct version of the package you want to install

    1. Search under Homebrew > Homebrew-core > Formula on Github

    2. In the history of the opencv.rb file: https://github.com/Homebrew/homebrew-core/commits/master/Formula/opencv.rb

      • Select the commit you want corresponding to the desired version, say opencv: update 4.6.0_1 bottle. and View file.
      • Copy the contents of / Download the file
  3. Open the .rb file on your system: brew edit opencv@4

  4. Replace the contents of this file with the file you downloaded from Github

  5. Install the package again using the .rb file path: brew install /opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/opencv.rb

This worked perfectly for me, whereas, @Lance's answer using brew install gave an Error: Your Command Line Tools (CLT) does not support macOS 13.

None of the other answers worked for me either.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文