自制程序是否安装了特定版本的公式? [英] Homebrew install specific version of formula?

查看:97
本文介绍了自制程序是否安装了特定版本的公式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How do I install a specific version of a formula in homebrew? For example, postgresql-8.4.4 instead of the latest 9.0.

推荐答案

TLDR: brew install postgresql@8.4.4请参见在下面回答以获取更多详细信息.

TLDR: brew install postgresql@8.4.4 See answer below for more details.

*(我已对答案进行了重新编辑,以提供更彻底的工作流程,以使用Homebrew安装/使用较旧的软件版本.如果发现较旧的版本更好,请随时添加注释. )

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

Let’s start with the simplest case:

自制软件安装新公式后,会将其放在版本化目录中,例如/usr/local/Cellar/postgresql/9.3.1.然后,将仅全局安装指向该文件夹的符号链接.原则上,这使得在两个已安装版本之间切换非常容易. (*)

When homebrew installs a new formula, it puts it in a versioned directory like /usr/local/Cellar/postgresql/9.3.1. Only symbolic links to this folder are then installed globally. In principle, this makes it pretty easy to switch between two installed versions. (*)

如果您使用Homebrew的时间更长,并且从未删除过旧版本(例如,使用brew cleanup),则可能是程序的某些旧版本仍然存在.如果您只想激活先前的版本,则brew switch是执行此操作的最简单方法.

If you have been using homebrew for longer and never removed older versions (using, for example brew cleanup), chances are that some older version of your program may still be around. If you want to simply activate that previous version, brew switch is the easiest way to do this.

brew info postgresql(或brew switch postgresql <TAB>)检查是否安装了旧版本:

Check with brew info postgresql (or brew switch postgresql <TAB>) whether the older version is installed:

$ 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 switch激活它:

We see that some older version is already installed. We may activate it using brew switch:

$ 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

让我们仔细检查一下已激活的内容:

Let’s double-check what is activated:

$ 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

请注意,星星*已移至新激活的版本

Note that the star * has moved to the newly activated version

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

(*) Please note that brew switch only works as long as all dependencies of the older version are still around. In some cases, a rebuild of the older version may become necessary. Therefore, using brew switch is mostly useful when one wants to switch between two versions not too far apart.

尤其对于大型软件项目,很可能对某个软件的几个(可能与API不兼容)主要版本有足够高的需求.自2012年3月起, Homebrew 0.9 为此提供了一种机制:brew tap& ; 自制版本存储库.

Especially for larger software projects, it is very probably that there is a high enough demand for several (potentially API incompatible) major versions of a certain piece of software. As of March 2012, Homebrew 0.9 provides a mechanism for this: brew tap & the homebrew versions repository.

该版本存储库可能包括一些公式的较旧版本的反向移植. (通常只有大型的和著名的,但是它们当然也有几种PostgreSQL的公式.)

That versions repository may include backports of older versions for several formulae. (Mostly only the large and famous ones, but of course they’ll also have several formulae for postgresql.)

brew search postgresql将向您显示外观:

$ brew search postgresql
postgresql
homebrew/versions/postgresql8    homebrew/versions/postgresql91
homebrew/versions/postgresql9    homebrew/versions/postgresql92

我们只需输入以下内容即可安装

We can simply install it by typing

$ 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
# …

请注意,这会自动点击 homebrew/versions水龙头. (使用brew tap进行检查,使用brew untap homebrew/versions进行删除.)下面的内容是等效的:

Note that this has automatically tapped the homebrew/versions tap. (Check with brew tap, remove with brew untap homebrew/versions.) The following would have been equivalent:

$ brew tap homebrew/versions
$ brew install postgresql8

只要向后移植的版本公式保持最新,此方法可能是处理较旧软件的最佳方法.

As long as the backported version formulae stay up-to-date, this approach is probably the best way to deal with older software.

以下列出的大多数方法都是出于完整性考虑.两者都试图从酿造库中复活一些不死配方.由于依赖关系的更改,公式规范中的API更改或下载URL的更改,事情可能会或可能不会起作用.

The following approaches are listed mostly for completeness. Both try to resurrect some undead formula from the brew repository. Due to changed dependencies, API changes in the formula spec or simply a change in the download URL, things may or may not work.

由于整个公式目录都是一个git存储库,因此可以使用纯git命令安装特定版本.但是,我们需要找到一种方法来进行可使用旧版本的提交.

Since the whole formula directory is a git repository, one can install specific versions using plain git commands. However, we need to find a way to get to a commit where the old version was available.

a)历史时期

2011年8月至2014年10月之间,自制软件使用了brew versions命令,该命令将所有可用的版本及其各自的SHA哈希散发出来.从2014年10月开始,您必须先做一个brew tap homebrew/boneyard才能使用它.就像水龙头的名称所暗示的那样,您可能应该只在万不得已时才这样做.

Between August 2011 and October 2014, homebrew had a brew versions command, which spat out all available versions with their respective SHA hashes. As of October 2014, you have to do a brew tap homebrew/boneyard before you can use it. As the name of the tap suggests, you should probably only do this as a last resort.

例如

$ brew versions postgresql
Warning: brew-versions is unsupported and may be removed soon.
Please use the homebrew-versions tap instead:
  https://github.com/Homebrew/homebrew-versions
9.3.2    git checkout 3c86d2b Library/Formula/postgresql.rb
9.3.1    git checkout a267a3e Library/Formula/postgresql.rb
9.3.0    git checkout ae59e09 Library/Formula/postgresql.rb
9.2.4    git checkout e3ac215 Library/Formula/postgresql.rb
9.2.3    git checkout c80b37c Library/Formula/postgresql.rb
9.2.2    git checkout 9076baa Library/Formula/postgresql.rb
9.2.1    git checkout 5825f62 Library/Formula/postgresql.rb
9.2.0    git checkout 2f6cbc6 Library/Formula/postgresql.rb
9.1.5    git checkout 6b8d25f Library/Formula/postgresql.rb
9.1.4    git checkout c40c7bf Library/Formula/postgresql.rb
9.1.3    git checkout 05c7954 Library/Formula/postgresql.rb
9.1.2    git checkout dfcc838 Library/Formula/postgresql.rb
9.1.1    git checkout 4ef8fb0 Library/Formula/postgresql.rb
9.0.4    git checkout 2accac4 Library/Formula/postgresql.rb
9.0.3    git checkout b782d9d Library/Formula/postgresql.rb

如您所见,建议不要使用它. Homebrew利用其内部启发法吐出可以找到的所有版本,并向您展示了一种检索旧公式的方法.试试吧.

As you can see, it advises against using it. Homebrew spits out all versions it can find with its internal heuristic and shows you a way to retrieve the old formulae. Let’s try it.

# 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版本,我们可以重新安装最新的公式以保持存储库的清洁:

Now that the older postgresql version is installed, we can re-install the latest formula in order to keep our repository clean:

$ git checkout -- Library/Formula/postgresql.rb

brew switch是您的朋友,可以在新旧之间切换.

brew switch is your friend to change between the old and the new.

b)史前时代

如果有特殊需要,我们也可以尝试通过自制软件仓库进行挖掘.

For special needs, we may also try our own digging through the homebrew repo.

$ 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'的所有提交.结果是两次提交.

git log -S looks for all commits in which the string '8.4.4' was either added or removed in the file Library/Taps/homebrew/homebrew-core/Formula/postgresql.rb. We get two commits as a result.

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的有效性) :

Obviously, fa992c6a82eebdc4cc36a0c0d2837f4c02f3f422 is the commit we’re interested in. As this commit is pretty old, we’ll try to downgrade the complete homebrew installation (that way, the formula API is more or less guaranteed to be valid):

$ git checkout -b postgresql-8.4.4 fa992c6a82eebdc4cc36a0c0d2837f4c02f3f422
$ brew install postgresql
$ git checkout master
$ git branch -d postgresql-8.4.4

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

You may skip the last command to keep the reference in your git repository.

一个注意事项:当签出较早的提交时,您会暂时降级自制软件的安装.因此,您应该小心,因为自制软件中的某些命令可能与最新版本不同.

One note: When checking out the older commit, you temporarily downgrade your homebrew installation. So, you should be careful as some commands in homebrew might be different to the most recent version.

这不太难,然后您可能会将其上传到您自己的存储库.曾经是 Homebrew-Versions ,但现在已终止.

It’s not too hard and you may then upload it to your own repository. Used to be Homebrew-Versions, but that is now discontinued.

如果要保留某个特定版本(例如postgresql),并在执行自然的brew update; brew upgrade过程时阻止其更新,则可以固定公式:

If you want to keep a certain version of, say postgresql, around and stop it from being updated when you do the natural brew update; brew upgrade procedure, you can pin a formula:

$ brew pin postgresql

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

Pinned formulae are listed in /usr/local/Library/PinnedKegs/ and once you want to bring in the latest changes and updates, you can unpin it again:

$ brew unpin postgresql

这篇关于自制程序是否安装了特定版本的公式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆