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


当前回答

这里的其他答案很好,但如果您需要安装较旧版本的软件包并确保修改了软件包名称,则需要另一种方法。当使用脚本(在我的例子中是PHP构建脚本)时,这一点非常重要,这些脚本使用brew前缀package_name来确定要用于编译的目录。

如果您正在使用brew提取,则会在包名称的末尾添加一个版本,这将中断brew前缀查找。

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

# uninstall the newer version of the package that you accidentally installed
brew uninstall --ignore-dependencies icu4c

# `extract` the version you'd like to install into a custom tap
brew tap-new $USER/local-tap
brew extract --version=68.2 icu4c $USER/local-tap

# jump into the new tap you created
cd $(brew --repository $USER/local-tap)/Formula

# rename the formula
mv icu4c@68.2.rb icu4c.rb

# change the name of the formula by removing "AT682" from the `class` definition
# the exact text you'll need to remove will be different
# depending on the version you extracted
nano icu4c.rb

# then, install this specific formula directly
brew install $(brew --repository $USER/local-tap)/Formula/icu4c.rb

我在这里写了更多。

其他回答

编辑:2021,由于github安装被弃用,这个答案不再起作用。(感谢蒂姆·史密斯的更新)。

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

查找本地自制程序gitdir或本地克隆homebrew/homebrew内核

cd/usr/local/Homebrew/Library/Taps/Homebrew/Homebrew内核/

OR

git克隆git@github.com:Homebrew/Homebrew-core.git

列出所有可用版本

git log master--Formula/flyway.rb

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

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

基于@tschundee和@Debilski的更新1所描述的工作流,我自动化了该过程,并在此脚本中添加了清理。

下载它,将其放到您的路径中,然后brewv<formula_name><wanted_version>。对于特定OP,它将是:

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

:)

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

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

用法:

brewv.sh formula_name desired_version

我刚刚将一个较旧版本的弹性搜索复制到/usr/local/Cellar/lelasticsearch目录中。

$ mkdir /usr/local/Cellar/elasticsearch/5.4.3/bin
$ cp elasticsearch /usr/local/Cellar/elasticsearch/5.4.3/bin
$ brew switch elasticsearch 5.4.3

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