Installation 自制安装公式的特定版本?

Installation 自制安装公式的特定版本?,installation,versioning,homebrew,Installation,Versioning,Homebrew,如何在自制中安装特定版本的公式?例如,postgresql-8.4.4而不是最新的9.0。TLDR:brew安装postgresql@8.4.4有关更多详细信息,请参阅 *(我重新编辑了我的答案,为安装/使用带有自制软件的旧版本提供了更全面的工作流程。如果发现旧版本更好,请随意添加注释。) 让我们从最简单的情况开始: 1) 检查版本是否已安装(但未激活) 当homebrew安装新公式时,它会将其放在一个版本化目录中,如/usr/local/ceral/postgresql/9.3.1。然后,仅

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

TLDR:
brew安装postgresql@8.4.4
有关更多详细信息,请参阅


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

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

1) 检查版本是否已安装(但未激活) 当homebrew安装新公式时,它会将其放在一个版本化目录中,如
/usr/local/ceral/postgresql/9.3.1
。然后,仅全局安装指向此文件夹的符号链接。原则上,这使得在两个已安装版本之间切换非常容易。(*)

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

使用
brew信息postgresql
(或
brew开关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开关
激活它:

$ 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
请注意,star
*
已移动到新激活的版本

(*)请注意,
brew switch
仅在旧版本的所有依赖项仍然存在时才起作用。在某些情况下,可能需要重建旧版本。因此,当您希望在相距不太远的两个版本之间切换时,使用
brew switch
最为有用

2) 检查版本是否可用作点击 特别是对于大型软件项目,很可能对某个软件的几个主要版本(可能与API不兼容)有足够高的需求。自2012年3月起,提供了一种机制:
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
# …
请注意,这会自动点击
自制/versions
点击。(用
brew点击查看,用
brew解除对自制软件/版本的映射删除)以下内容应是等效的:

$ brew tap homebrew/versions
$ brew install postgresql8
只要后端口版本公式保持最新,这种方法可能是处理旧软件的最佳方法

3) 试试过去的一些公式 下面列出的方法主要是为了完整性。两者都试图从brew存储库中复活一些不死公式。由于更改了依赖项、公式规范中的API更改或下载URL中的简单更改,事情可能会发生,也可能不会发生

由于整个formula目录是一个git存储库,因此可以使用普通git命令安装特定版本。但是,我们需要找到一种方法,在旧版本可用的情况下进行提交

a)历史时期

在2011年8月至2014年10月期间,homebrew有一个
brew versions
命令,该命令使用各自的SHA散列输出所有可用版本。从2014年10月起,您必须先进行
brew,然后点击自制/boneyard
,才能使用它。正如tap的名称所示,您可能只应该在万不得已的情况下这样做

例如

正如你所看到的,它建议不要使用它。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
是您在新旧之间切换的朋友

史前时代

对于特殊需求,我们也可以尝试通过自制回购协议进行挖掘

$ cd Library/Taps/homebrew/homebrew-core && git log -S'8.4.4' -- Formula/postgresql.rb
git log-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
是我们感兴趣的提交。由于此提交非常旧,我们将尝试降级整个自制安装(这样,formula API或多或少保证有效):

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

注意:在签出旧的提交时,您会临时降级您的自制安装。因此,您应该小心,因为自制软件中的某些命令可能与最新版本不同

4) 手动编写公式 然后,您可以将其上载到自己的存储库中。过去是,但现在已经停止了

奖励:钉住 如果您想保留特定版本的,例如postgresql,并在执行自然
brew更新时阻止其更新;brew升级
过程中,您可以键入公式:

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

$ brew unpin postgresql

TLDR:
brew安装postgresql@8.4.4
有关更多详细信息,请参阅


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

让我们从最简单的情况开始:
$ brew pin postgresql
$ brew unpin postgresql
http://ftp2.uk.postgresql.org/sites/ftp.postgresql.org/source/v8.4.6/postgresql-8.4.6.tar.bz2
fcc3daaf2292fa6bf1185ec45e512db6
brew install postgres
initdb /usr/local/var/postgres
kern.sysv.shmall=65536
kern.sysv.shmmax=16777216
launchctl load -w /usr/local/Cellar/postgresql/8.4.6/org.postgresql.postgres.plist
brew install https://raw.github.com/Homebrew/homebrew-versions/master/postgresql8.rb
brew install https://raw.github.com/Homebrew/homebrew-versions/master/mysql51.rb
brew switch [formula] [version]
brew switch node 0.4.12
brew switch node 0.6.5
$ brew unlink maven $ 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 $ 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 install postgresql@9.5
$ brew search postgresql@
==> Searching local taps...
postgresql@10.1 ✔     postgresql@9.4        postgresql@9.5        postgresql@9.6
cd path/to/downloaded/script/
./brewv postgresql 8.4.4
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
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)
...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
git reset HEAD docker-machine.rb
git checkout -- docker-machine.rb
$ 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)
$ 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
 $ brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/c77882756a832ac1d87e7396c114158e5619016c/Formula/mysql.rb
cd `brew --prefix`
git log Library/Formula/python.rb
commit 9ff2d8ca791ed1bd149fb8be063db0ed6a67a6de
Author: Dominyk Tiller <dominyktiller@gmail.com>
Date:   Thu Jun 30 17:42:18 2016 +0100

    python: clarify pour_bottle reason

commit cb3b29b824a264895434214e191d0d7ef4d51c85
Author: BrewTestBot <brew-test-bot@googlegroups.com>
Date:   Wed Jun 29 14:18:40 2016 +0100

    python: update 2.7.12 bottle.

commit 45bb1e220341894bbb7de6fd3f6df20987dc14f0
Author: Rakesh <rakkesh@users.noreply.github.com>
Date:   Wed Jun 29 10:02:26 2016 +0530

    python 2.7.12

    Closes #2452.

    Signed-off-by: Tim D. Smith <git@tim-smith.us>

commit cf5da0547cd261f79d69e7ff62fdfbd2c2d646e9
Author: BrewTestBot <brew-test-bot@googlegroups.com>
Date:   Fri Jun 17 20:14:36 2016 +0100

    python: update 2.7.11 bottle.

...
git checkout cf5da05
brew install python
git checkout master
$ 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
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›
brew info ‹formula› | grep ^From:
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/‹hash›/Formula/‹formula›.rb
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
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 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.
> brew edit icu4c
# drops you to editor
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"
brewv.sh formula_name desired_version
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.
# 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
brew services stop postgresql
brew install postgresql@11
brew link postgresql@11 --force
cd /usr/local/var
ls -lh
mv postgresql@11 postgresql@11-fresh-backup
mv postgres postgresql@11
brew services start postgresql@11
$ brew-install-specific pkg@a.b.c
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: 
Select index: 2
Run:
  brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/<COMMIT-SHA>/Formula/pkg.rb
# 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
brew extract --version=8.4p1  openssh homebrew/cask
brew install openssh@8.4p1