如何在自制程序中安装特定版本的公式?例如,postgresql-8.4.4而不是最新的9.0。
当前回答
我已经尝试了这里的大多数解决方案,但它们已经过时了。我不得不把这里的一些想法与我自己的工作结合起来。因此,我创建了一个脚本来帮助我完成你可以在这里找到的繁重任务
用法:
brewv.sh formula_name desired_version
其他回答
这些都不适用于我的案例(Python),所以我将添加我的2美分:
cd `brew --prefix`
git log Library/Formula/python.rb
输出如下所示:
提交文件作者:Dominik Tiller<dominyktiller@gmail.com>日期:2016年6月30日星期四17:42:18+0100python:澄清pour-bottle原因提交cb3b29b824a264895434214e191d0d7ef4d51c85作者:BrewTestBot<brew-test-bot@googlegroups.com>日期:2016年6月29日星期三14:18:40+0100python:更新2.7.12瓶。提交45bb1e20234184bbb7d6fd3f6df20987dc14f0作者:Rakesh<rakkesh@users.noreply.github.com>日期:2016年6月29日星期三10:02:26+0530python 2.7.12关闭#2452。签字人:Tim D.Smith<git@tim-smith.us>提交cf5da0547cd261f79d69e7ff62fdfbd2c2d646e9作者:BrewTestBot<brew-test-bot@googlegroups.com>日期:2016年6月17日星期五20:14:36+0100python:更新2.7.11瓶子。...
我想要2.7.11版本,所以我的哈希是cf5da0547cd261f79d69e7ff62fdfbd2c2d646e9(简称cf5da05)。接下来,我检查该版本并安装公式python:
git checkout cf5da05
brew install python
最后,清理:
git checkout master
TLDR:brew安装postgresql@8.4.4有关更多详细信息,请参阅下面的答案。
*(我已经重新编辑了我的答案,以便为安装/使用自制软件的旧版本提供更全面的工作流程。如果您发现旧版本更好,请随时添加备注。)
让我们从最简单的案例开始:
1) 检查版本是否已安装(但未激活)
当自制程序安装一个新公式时,它会将其放在版本化的目录中,如/usr/local/Cellar/postgresql/9.3.1。然后,仅全局安装指向此文件夹的符号链接。原则上,这使得在两个已安装版本之间切换非常容易。(*)
如果您使用自制程序的时间较长,并且从未删除过旧版本(例如,使用brew cleanup),那么您的程序的某些旧版本可能仍然存在。如果您想简单地激活以前的版本,brew开关是最简单的方法。
使用brew-info-postgresql(或brew-switch-postgresql<TAB>)检查是否安装了旧版本:
$ brew info postgresql
postgresql: stable 9.3.2 (bottled)
http://www.postgresql.org/
Conflicts with: postgres-xc
/usr/local/Cellar/postgresql/9.1.5 (2755 files, 37M)
Built from source
/usr/local/Cellar/postgresql/9.3.2 (2924 files, 39M) *
Poured from bottle
From: https://github.com/Homebrew/homebrew/commits/master/Library/Formula/postgresql.rb
# … and some more
我们看到已经安装了一些旧版本。我们可以使用brew开关激活它:
$ brew switch postgresql 9.1.5
Cleaning /usr/local/Cellar/postgresql/9.1.5
Cleaning /usr/local/Cellar/postgresql/9.3.2
384 links created for /usr/local/Cellar/postgresql/9.1.5
让我们仔细检查激活的内容:
$ brew info postgresql
postgresql: stable 9.3.2 (bottled)
http://www.postgresql.org/
Conflicts with: postgres-xc
/usr/local/Cellar/postgresql/9.1.5 (2755 files, 37M) *
Built from source
/usr/local/Cellar/postgresql/9.3.2 (2924 files, 39M)
Poured from bottle
From: https://github.com/Homebrew/homebrew/commits/master/Library/Formula/postgresql.rb
# … and some more
请注意,星号*已移至新激活的版本
(*)请注意,brew开关仅在旧版本的所有依赖项仍然存在的情况下工作。在某些情况下,可能需要重建旧版本。因此,当想要在两个相距不太远的版本之间切换时,使用brew开关最有用。
2) 检查版本是否可用
特别是对于大型软件项目,很可能对某个软件的几个(可能不兼容API)主要版本有足够高的需求。截至2012年3月,Homebrew 0.9提供了一种机制:brew tap和自制版本存储库。
该版本存储库可能包含多个公式的旧版本的后端。(大多数只有大型和著名的,但当然,它们也有几个postgresql公式。)
brew search postgresql将向您显示查找位置:
$ brew search postgresql
postgresql
homebrew/versions/postgresql8 homebrew/versions/postgresql91
homebrew/versions/postgresql9 homebrew/versions/postgresql92
我们可以通过键入
$ brew install homebrew/versions/postgresql8
Cloning into '/usr/local/Library/Taps/homebrew-versions'...
remote: Counting objects: 1563, done.
remote: Compressing objects: 100% (943/943), done.
remote: Total 1563 (delta 864), reused 1272 (delta 620)
Receiving objects: 100% (1563/1563), 422.83 KiB | 339.00 KiB/s, done.
Resolving deltas: 100% (864/864), done.
Checking connectivity... done.
Tapped 125 formula
==> Downloading http://ftp.postgresql.org/pub/source/v8.4.19/postgresql-8.4.19.tar.bz2
# …
请注意,这已经自动点击自制程序/版本。(使用brew tap进行检查,使用brew untap自制程序/版本进行删除。)以下内容等效:
$ brew tap homebrew/versions
$ brew install postgresql8
只要后端口版本公式保持最新,这种方法可能是处理旧软件的最佳方法。
3) 尝试一些过去的公式
列出以下方法主要是为了完整性。两人都试图从酿造库中复活一些不死配方。由于依赖关系的改变,公式规范中的API改变,或者下载URL的改变,事情可能会发生,也可能不会发生。
由于整个公式目录是一个git存储库,因此可以使用普通的git命令安装特定版本。然而,我们需要找到一种方法,在旧版本可用的地方进行提交。
a) 历史性时代
在2011年8月至2014年10月期间,自制程序有一个brew版本命令,它会将所有可用版本与各自的SHA散列一起输出。从2014年10月起,你必须在使用之前先自制/装骨机。正如水龙头的名称所暗示的,你可能只能在万不得已的情况下这样做。
E.g.
$ brew versions postgresql
Warning: brew-versions is unsupported and may be removed soon.
Please use the homebrew-versions tap instead:
https://github.com/Homebrew/homebrew-versions
9.3.2 git checkout 3c86d2b Library/Formula/postgresql.rb
9.3.1 git checkout a267a3e Library/Formula/postgresql.rb
9.3.0 git checkout ae59e09 Library/Formula/postgresql.rb
9.2.4 git checkout e3ac215 Library/Formula/postgresql.rb
9.2.3 git checkout c80b37c Library/Formula/postgresql.rb
9.2.2 git checkout 9076baa Library/Formula/postgresql.rb
9.2.1 git checkout 5825f62 Library/Formula/postgresql.rb
9.2.0 git checkout 2f6cbc6 Library/Formula/postgresql.rb
9.1.5 git checkout 6b8d25f Library/Formula/postgresql.rb
9.1.4 git checkout c40c7bf Library/Formula/postgresql.rb
9.1.3 git checkout 05c7954 Library/Formula/postgresql.rb
9.1.2 git checkout dfcc838 Library/Formula/postgresql.rb
9.1.1 git checkout 4ef8fb0 Library/Formula/postgresql.rb
9.0.4 git checkout 2accac4 Library/Formula/postgresql.rb
9.0.3 git checkout b782d9d Library/Formula/postgresql.rb
正如你所看到的,它建议不要使用它。Homebrew用它的内部启发式方法吐出了它能找到的所有版本,并向你展示了一种检索旧公式的方法。让我们试试看。
# First, go to the homebrew base directory
$ cd $( brew --prefix )
# Checkout some old formula
$ git checkout 6b8d25f Library/Formula/postgresql.rb
$ brew install postgresql
# … installing
现在安装了旧的postgresql版本,我们可以重新安装最新的公式,以保持存储库的清洁:
$ git checkout -- Library/Formula/postgresql.rb
brew switch是你在新旧之间转换的朋友。
b) 史前时代
对于特殊需求,我们也可以尝试自己通过自制回购进行挖掘。
$ cd Library/Taps/homebrew/homebrew-core && git log -S'8.4.4' -- Formula/postgresql.rb
gitlog-S查找文件Library/Taps/homebrew/homebrew core/Formula/postgresql.rb中添加或删除了字符串“8.4.4”的所有提交。结果得到两次提交。
commit 7dc7ccef9e1ab7d2fc351d7935c96a0e0b031552
Author: Aku Kotkavuo
Date: Sun Sep 19 18:03:41 2010 +0300
Update PostgreSQL to 9.0.0.
Signed-off-by: Adam Vandenberg
commit fa992c6a82eebdc4cc36a0c0d2837f4c02f3f422
Author: David Höppner
Date: Sun May 16 12:35:18 2010 +0200
postgresql: update version to 8.4.4
显然,fa992c6a82eebdc4cc36a0c0d2837f4c02f3f422是我们感兴趣的提交。由于这个提交很旧,我们将尝试降级完整的自制程序安装(这样,公式API或多或少保证有效):
$ git checkout -b postgresql-8.4.4 fa992c6a82eebdc4cc36a0c0d2837f4c02f3f422
$ brew install postgresql
$ git checkout master
$ git branch -d postgresql-8.4.4
您可以跳过最后一个命令,将引用保存在git存储库中。
一个注意事项:在检查旧的提交时,您会暂时降级自制程序的安装。因此,您应该小心,因为自制程序中的某些命令可能与最新版本不同。
4) 手动编写公式
这并不太难,然后您可以将其上传到自己的存储库中。以前是自制版本,但现在已经停产。
A.)奖金:固定
如果你想保留的某个版本,比如postgresql,在你进行自然酿造更新时停止更新;brew升级程序,您可以固定公式:
$ brew pin postgresql
固定公式列在/usr/local/Library/PinnedKegs/中,一旦您希望引入最新的更改和更新,就可以再次取消固定:
$ brew unpin postgresql
对于当前不在默认酿造配方中的版本,您可以使用以下工具轻松创建自己的水龙头:https://github.com/buildtools-version-taps/homebrew-versions-tap-tool
如果无法使用brew search<formula>找到您的版本,您也可以尝试查看公式的提交日志,以找到所需的版本:
下面是通过brew安装旧版本nginx的示例:
ngxnx公式提交日志参见nginx:更新1.6.3瓶装eba75b9a1a474b9fc4df30bd0a32637fa31ec049
从那里,我们可以使用sha和原始git url安装1.6.3:
brew安装https://raw.githubusercontent.com/Homebrew/homebrew/eba75b9a1a474b9fc4df30bd0a32637fa31ec049/Library/Formula/nginx.rb
UPDATE:此方法已弃用,不再有效。
此方法导致错误:不支持从GitHub提交URL安装mysql!brew将mysql提取到GitHub上的稳定水龙头。(用法错误)
$ brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/c77882756a832ac1d87e7396c114158e5619016c/Formula/mysql.rb
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core and homebrew/cask).
...
Traceback (most recent call last):
9: from /usr/local/Homebrew/Library/Homebrew/brew.rb:122:in `<main>'
8: from /usr/local/Homebrew/Library/Homebrew/cmd/install.rb:132:in `install'
7: from /usr/local/Homebrew/Library/Homebrew/cli/parser.rb:302:in `parse'
6: from /usr/local/Homebrew/Library/Homebrew/cli/parser.rb:651:in `formulae'
5: from /usr/local/Homebrew/Library/Homebrew/cli/parser.rb:651:in `map'
4: from /usr/local/Homebrew/Library/Homebrew/cli/parser.rb:655:in `block in formulae'
3: from /usr/local/Homebrew/Library/Homebrew/formulary.rb:351:in `factory'
2: from /usr/local/Homebrew/Library/Homebrew/formulary.rb:138:in `get_formula'
1: from /usr/local/Homebrew/Library/Homebrew/formulary.rb:142:in `klass'
/usr/local/Homebrew/Library/Homebrew/formulary.rb:227:in `load_file': Invalid usage: Installation of mysql from a GitHub commit URL is unsupported! `brew extract mysql` to a stable tap on GitHub instead. (UsageError)
12: from /usr/local/Homebrew/Library/Homebrew/brew.rb:155:in `<main>'
11: from /usr/local/Homebrew/Library/Homebrew/brew.rb:157:in `rescue in <main>'
10: from /usr/local/Homebrew/Library/Homebrew/help.rb:64:in `help'
9: from /usr/local/Homebrew/Library/Homebrew/help.rb:83:in `command_help'
8: from /usr/local/Homebrew/Library/Homebrew/help.rb:103:in `parser_help'
7: from /usr/local/Homebrew/Library/Homebrew/cli/parser.rb:302:in `parse'
6: from /usr/local/Homebrew/Library/Homebrew/cli/parser.rb:651:in `formulae'
5: from /usr/local/Homebrew/Library/Homebrew/cli/parser.rb:651:in `map'
4: from /usr/local/Homebrew/Library/Homebrew/cli/parser.rb:655:in `block in formulae'
3: from /usr/local/Homebrew/Library/Homebrew/formulary.rb:351:in `factory'
2: from /usr/local/Homebrew/Library/Homebrew/formulary.rb:138:in `get_formula'
1: from /usr/local/Homebrew/Library/Homebrew/formulary.rb:142:in `klass'
/usr/local/Homebrew/Library/Homebrew/formulary.rb:227:in `load_file': Invalid usage: Installation of mysql from a GitHub commit URL is unsupported! `brew extract mysql` to a stable tap on GitHub instead. (UsageError)
我尝试使用推荐的命令进行安装,但它在MySQL 5.7.10的这个特定实例中不起作用。你可能会有更好的运气与更新的公式。
$ brew extract --version=5.7.10 mysql homebrew/cask
==> Searching repository history
==> Writing formula for mysql from revision 0fa511b to:
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Formula/mysql@5.7.10.rb
$
$ brew install /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Formula/mysql@5.7.10.rb
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
Updated 1 formula.
Error: undefined method `core_tap?' for nil:NilClass
Error: Failed to load cask: /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Formula/mysql@5.7.10.rb
Cask 'mysql@5.7.10' is unreadable: wrong constant name #<Class:0x00007f9b9498cad8>
Warning: Treating /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Formula/mysql@5.7.10.rb as a formula.
==> Installing mysql@5.7.10 from homebrew/cask
==> Downloading https://homebrew.bintray.com/bottles/cmake-3.19.4.big_sur.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/278f2ad1caf664019ff7b4a7fc5493999c06adf503637447af13a617d45cf484?response-content-disposition=attachment%3Bfilenam
######################################################################## 100.0%
==> Downloading https://downloads.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.bz2
==> Downloading from https://phoenixnap.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.bz2
######################################################################## 100.0%
==> Downloading https://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.10.tar.gz
curl: (22) The requested URL returned error: 404 Not Found
Error: Failed to download resource "mysql@5.7.10"
Download failed: https://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.10.tar.gz
您可以在上面的路径中修改公式(用ruby编写),以尝试实现所需的结果(例如,在最近的macOS版本上安装MySQL 5.7.10)。
您可以使用识别公式和公式历史记录中与您要安装的软件包版本匹配的特定提交的策略。
去https://github.com/Homebrew/homebrew-core按键盘上的t启动文件查找器。确定一个看起来最相关的公式,可能是:formula/mysql.rb,将您带到forumla文件位置:https://github.com/Homebrew/homebrew-core/blob/master/Formula/mysql.rb.单击历史记录按钮查看修订历史记录,该按钮位于https://github.com/Homebrew/homebrew-core/commits/master/Formula/mysql.rb.如果您对MySQL 5.7.10感兴趣,可以单击5.7.11之前的最新版本,该版本导航到GitHub提交:
https://github.com/Homebrew/homebrew-core/commit/c77882756a832ac1d87e7396c114158e5619016c#Formula/mysql.rb
注意:如果提交历史没有加载到浏览器中,您可能需要根据GitHub的建议在控制台中查看提交历史。如果您有兴趣在GitHub上看到提交,请在URL中替换上面的提交SHA。或者,跳到下面的步骤7。
应用提交后,单击“查看”按钮查看mysql.rb文件的源代码。然后单击“原始”按钮查看原始源。复制URL。或者,使用mysql.rb文件名自己构建URL,以标识您的公式和该公式的特定版本(由以下URL中的commmit SHA标识)。
https://raw.githubusercontent.com/Homebrew/homebrew-core/c77882756a832ac1d87e7396c114158e5619016c/Formula/mysql.rb
使用$brew Install[步骤7的URL]安装它$brew安装https://raw.githubusercontent.com/Homebrew/homebrew-core/c77882756a832ac1d87e7396c114158e5619016c/Formula/mysql.rb
推荐文章
- 我如何安装imagemagick与自制?
- 我如何知道哪些自制配方是可升级的?
- "ERROR:root:code for hash md5 was not found"当使用任何hg mercurial命令时
- homebrew、macports或其他软件包安装工具的区别/用途是什么?
- Ruby Bundle Symbol not found: _SSLv2_client_method (LoadError)
- Virtualenvs中的破引用
- brew install XXX和brew cask install XXX有什么区别
- Brew安装docker不包括docker引擎?
- 我如何使用brew安装Python作为默认的Python?
- 如何用自制程序更新公式?
- 在安装Homebrew后,我得到' zsh:命令未找到:brew '
- 升级所有通过家酿桶安装的桶
- 如何在OSX上更新Xcode到最新版本?
- 如何找到Homebrew的可安装软件包列表?
- 错误2002 (HY000):无法通过套接字/tmp/ MySQL .sock连接到本地MySQL服务器