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


当前回答

按照@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。

我刚刚使用Homebrew返回到Maven 2.2.1,因为简单的brew安装Maven安装了Maven 3.0.3。

首先你必须把maven目录放在那里

$ brew unlink maven

使用brew tap命令

$ 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

现在,您可以安装maven2公式:

$ 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" 

编辑:您也可以只编写switch maven 2.2.1来切换到不同的版本。

编辑:Apache Maven项目重组了他们的repo。更新此答案以说明此更改。

按照@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

更新日期:2015年1月15日

查找所需软件和版本的提交历史记录。例如,我需要从docker版本1.4.1切换到1.3.3:https://github.com/Homebrew/homebrew-core/commits/master/Formula/docker.rb使用此按钮查看文件:单击“原始”按钮:从地址栏复制URL(本例中为docker.rb URL)brew install<url>(可能必须首先brew unlink,例如brew unlinkdocker)酿造开关装卸工1.3.3切换回码头1.4.1酿造切换码头1.4.1

根据这一要点

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

更新Library/Formal/postgresql.rb第8行至

http://ftp2.uk.postgresql.org/sites/ftp.postgresql.org/source/v8.4.6/postgresql-8.4.6.tar.bz2

第9行的MD5

fcc3daaf2292fa6bf1185ec45e512db6

保存并退出。

brew install postgres
initdb /usr/local/var/postgres

现在在这个阶段,您可能会遇到postgresql无法创建共享内存段错误,要解决这个问题,请像这样更新/etc/sysctl.conf:

kern.sysv.shmall=65536
kern.sysv.shmmax=16777216

再次尝试initdb/usr/local/var/postgres,它应该运行平稳。

在启动时运行postgresql

launchctl load -w /usr/local/Cellar/postgresql/8.4.6/org.postgresql.postgres.plist

希望有助于:)