检查brew info postgresql(或brew switch postgresql <TAB>)是否安装了旧版本:
$ brew info postgresqlpostgresql: 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 bottleFrom: https://github.com/Homebrew/homebrew/commits/master/Library/Formula/postgresql.rb# … and some more
我们看到已经安装了一些旧版本。我们可以使用brew switch激活它:
$ brew switch postgresql 9.1.5Cleaning /usr/local/Cellar/postgresql/9.1.5Cleaning /usr/local/Cellar/postgresql/9.3.2384 links created for /usr/local/Cellar/postgresql/9.1.5
让我们仔细检查激活的内容:
$ brew info postgresqlpostgresql: 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 bottleFrom: https://github.com/Homebrew/homebrew/commits/master/Library/Formula/postgresql.rb# … and some more
# 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
commit 7dc7ccef9e1ab7d2fc351d7935c96a0e0b031552Author: Aku KotkavuoDate: Sun Sep 19 18:03:41 2010 +0300
Update PostgreSQL to 9.0.0.
Signed-off-by: Adam Vandenberg
commit fa992c6a82eebdc4cc36a0c0d2837f4c02f3f422Author: David HöppnerDate: Sun May 16 12:35:18 2010 +0200
postgresql: update version to 8.4.4
brew tap homebrew/versionsbrew install subversion17 # for svn 1.7 branch instead of last availablebrew install postgresql8 # for postgresql 8 (which you ask)
转到您的自制#0目录。 您可以通过运行brew info [any package name]来确定这一点。例如,brew info docker-machine给我一条线,显示我路径-/usr/local/Cellar/docker-machine/0.5.0。这告诉我在我的机器上,自制安装在/usr/local和Formula目录默认位于/usr/local/Library/Formula
$ brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/c77882756a832ac1d87e7396c114158e5619016c/Formula/mysql.rbUpdating 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)
$ 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.rbUpdating Homebrew...==> Auto-updated Homebrew!Updated 1 tap (homebrew/core).==> Updated FormulaeUpdated 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.rbCask '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 FoundError: Failed to download resource "mysql@5.7.10"Download failed: https://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.10.tar.gz
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 versionsbrew log --format=format:%H\ %s -F --grep=‹version› ‹formula›
这将显示一个提交哈希列表。取一个合适的(通常它应该非常明显,通常是最近的(即顶部)。
查找公式位于上游存储库中的URL:
brew info ‹formula› | grep ^From:
Fix the URL:
Replace github.com with raw.githubusercontent.com
Replace blob/master with the commit hash we found in the first step.
Install the desired version by replacing master in the previously found URL by the commit hash, e.g.:
(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=32353d2286f850fd965e0a48bcf692b83a6e9a41BREW_FORMULA_NAME=bashbrew 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
brew tap-new username/repo-name# extract with a version seems to run a grep under the hoodbrew extract --version='4.4.23' bash username/repo-namebrew install bash@4.4.23# 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.
这会在您的自定义点击中创建一个formula@version,您可以根据上述示例安装该点击。缺点是您可能仍然需要brew unlink bash然后brew link bash@4.4.23才能使用您的特定版本的Bash或任何其他公式。
brew tap-new $USER/local-tap# extract with a version seems to run a `git log --grep` under the hoodbrew extract --version=4.4.23 bash $USER/local-tap# Install your new version from the tapbrew 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 link bash@4.4.23才能使用您的特定版本的Bash(或安装了最新和旧版本的任何其他公式)。
# This search syntax works with newer Homebrewexport BREW_FORMULA_SEARCH_VERSION=4.4.23 BREW_FORMULA_NAME=bash# This will print any/all commits that match the version and formula namegit -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 downexport 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
# brew has a git repo on your localhostcd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
git remote -vorigin https://github.com/Homebrew/homebrew-core (fetch)origin https://github.com/Homebrew/homebrew-core (push)
# find the version of kops.rb you needgit log Formula/kops.rb
# checkout old commit# kops: update 1.18.1 bottle.git checkout 2f0ede7f27dfc074d5b5493894f3468f27cc73f0 -- Formula/kops.rb
brew unlink kopsbrew install kops
# now we have old version installedls -1 /usr/local/Cellar/kops/1.18.11.18.2
which kops/usr/local/bin/kopsls -l /usr/local/bin/kops/usr/local/bin/kops -> ../Cellar/kops/1.18.1/bin/kopskops versionVersion 1.18.1
# revert to the newest versionbrew uninstall kopsgit checkout -fbrew link kopskops versionVersion 1.18.2
# Please define variablespackageName=<packageName>packageVersion=<packageVersion>
# Create a new tabbrew tap-new local/$packageName
# Extract into local tapbrew extract --version=$packageVersion $packageName local/$packageName
# Verify packages is presentbrew search $packageName@
# Run brew install@version as usualbrew install local/$packageName/$packageName@$packageVersion
# uninstall the newer version of the package that you accidentally installedbrew uninstall --ignore-dependencies icu4c
# `extract` the version you'd like to install into a custom tapbrew tap-new $USER/local-tapbrew extract --version=68.2 icu4c $USER/local-tap
# jump into the new tap you createdcd $(brew --repository $USER/local-tap)/Formula
# rename the formulamv 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 extractednano icu4c.rb
# then, install this specific formula directlybrew install $(brew --repository $USER/local-tap)/Formula/icu4c.rb
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>