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


当前回答

以下是我如何降级KOPS(不支持版本控制)

# brew has a git repo on your localhost
cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core

git remote -v
origin  https://github.com/Homebrew/homebrew-core (fetch)
origin  https://github.com/Homebrew/homebrew-core (push)

# find the version of kops.rb you need
git log Formula/kops.rb

# checkout old commit
# kops: update 1.18.1 bottle.
git checkout 2f0ede7f27dfc074d5b5493894f3468f27cc73f0 -- Formula/kops.rb

brew unlink kops
brew install kops

# now we have old version installed
ls -1 /usr/local/Cellar/kops/
1.18.1
1.18.2

which kops
/usr/local/bin/kops
ls -l /usr/local/bin/kops
/usr/local/bin/kops -> ../Cellar/kops/1.18.1/bin/kops
kops version
Version 1.18.1

# revert to the newest version
brew uninstall kops
git checkout -f
brew link kops
kops version
Version 1.18.2

其他回答

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

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

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

:)

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

查找您要查找的库https://github.com/Homebrew/homebrew-core/tree/master/Formula单击它:https://github.com/Homebrew/homebrew-core/blob/master/Formula/postgresql.rb单击“历史记录”按钮查看旧提交:https://github.com/Homebrew/homebrew-core/commits/master/Formula/postgresql.rb单击所需的选项:“postgresql:update version to 8.4.4”,https://github.com/Homebrew/homebrew-core/blob/8cf29889111b44fd797c01db3cf406b0b14e858c/Formula/postgresql.rb单击“原始”链接:https://raw.githubusercontent.com/Homebrew/homebrew-core/8cf29889111b44fd797c01db3cf406b0b14e858c/Formula/postgresql.rbbrew安装https://raw.githubusercontent.com/Homebrew/homebrew-core/8cf29889111b44fd797c01db3cf406b0b14e858c/Formula/postgresql.rb

官方方法(从对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 bash@4.4.23
# Note this "fails" trying to grab a bottle for the package and seems to have
# some odd doubling of the version in that output, but this isn't fatal.

这将创建formula@version在您可以按照上面的示例安装的自定义抽头中。一个重要的注意事项是,如果您之前安装了默认/最新版本的公式,那么可能需要brew unlink bash,然后再brew linkbash@4.4.23以便使用您的特定版本的Bash(或安装了最新版本和较旧版本的任何其他公式)。

这种方法的一个潜在缺点是,你不能轻易地在不同版本之间来回切换,因为根据brew的说法,这是一种“不同的配方”。

如果你想使用酿造开关$FORMULA$VERSION,你应该使用下一个方法。


脚本化方法(推荐)

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

首先使用brew install bash安装最新版本的公式然后酿造unlink bash然后按照下面的代码段安装所需的旧版本最后使用brew开关bash 4.4.23设置到您版本的符号链接

如果您在安装旧版本后执行了brew升级,而没有先安装最新版本,那么最新版本的安装将与旧版本相冲突,除非您首先执行brew pin bash。

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

复制、粘贴和编辑下面代码段中的导出行,以更新所需的版本和公式名称,然后按原样复制和粘贴其余内容,它将使用这些变量来实现神奇的效果。

# 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。

解决方案

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

最新的openssl@8.5p1在我运行brew升级后出现错误,因此我通过上述方式成功地备份到了以前的版本。

家庭酿造最近发生了变化。以前有用的东西现在不管用了。我发现最简单的工作方式(2021 1月)是:

找到我的软件的.rb文件(首先转到公式,找到我需要的文件,然后单击“历史”;对于CMake,这是在https://github.com/Homebrew/homebrew-core/commits/master/Formula/cmake.rb)从修订中选择所需版本,例如3.18.4,单击.rb文件diff(…)右上角的三个点,然后单击Raw。复制URL。取消链接旧版本brew取消链接cmake直接从gitURL安装不再有效(brew-installhttps://raw.githubusercontent.com/Homebrew/homebrew-core/2bf16397f163187ae5ac8be41ca7af25b5b2e2cc/Formula/cmake.rb将失败)相反,下载它并从本地文件curl-O安装https://raw.githubusercontent.com/Homebrew/homebrew-core/2bf16397f163187ae5ac8be41ca7af25b5b2e2cc/Formula/cmake.rb&&brew安装/克马克.rb

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