Keg-only homebrew formulas
Today I installed the curl
formula via homebrew
, but after installing it (and re-sourcing the shell) i noticed that :
% which curl
/usr/bin/curl
as a matter of fact, the output of brew install curl
stated that it was a keg-only formula, and that since curl
was already present in OS X, it didn't link it into Homebrew prefix, as that could cause unspecified problems.
Then it proceeds stating that
Generally there are no consequences of this for you
I would like to know:
- What sorts of problems exactly?
- What is the purpose of installing keg-only formulas via Homebrew? How can there be no consequences if the newly开发者_如何学运维 installed tool is not in the
PATH
?
- Problems: if a homebrew application is put in the path in front of the default OS X version of the same, really anything might happen. Most common issues are caused by differences between the set of command line options available in the two versions, or differences in the meaning of the options. For curl the consequences might not be so bad, but for other applications you could, at worst, break the OS.
- Keg-only: now you have two versions of curl! The default OS X, and the homebrew. If you want to use features that are not in the default but in the homebrew, you can do so by calling the homebrew curl explicitly. The precise path depends on how you've got homebrew set up. Because the newly installed version is not in the path, its unlikely to cause a problem unless it is explicitly called.
I want to add some complement to the second problem(related to the mechanism of keg-only) asked by @asymmetric.
HomeBrew's prefix is /usr/local
, and HomeBrew keeps all installed kegs in the default directory, say /usr/local/Cellar
. In general, HomeBrew could create symlink for installed formula(non-keg-only formula), and the corresponding symlink is kept in /usr/local/bin
. This symlink-creation procedure is automatic when HomeBrew installing the formula. Here the path /usr/local/bin
would be called default (symlink) prefix.
On the other hand, according to FAQ of HomeBrew, we have the following guidance:
``keg-only formula is installed only into the Cellar and is not linked into the default prefix. This means most tools will not find it.''
But at the same time the HomeBrew creates symlinks in the directory /usr/local/opt
for ALL installed formulae no matter whether they are keg-only or not.
There will be two crucial points we should notice:
- By default the default (symlink) prefix
/usr/local/bin
is inPATH
, but the non-prefix/usr/local/opt
is NOT inPATH
. - By default the default (symlink) prefix
/usr/local/bin
in general points towards the latest version of formula. So if you want to use the specific version(often in keg-only format) of some formula you could temporarily prepend yourPATH
with the keg-only formula'sbin
directory, for example,export PATH="$(brew --prefix)/opt/FormulaName/bin:${PATH}"
.
The setting of /usr/local/opt
mentioned above could resolve the executable-conflict. In general, you might have a formula or program in your system with many different versions, such as the latest version and outdated version, the Apple native version and locally installed version, an so on. It's possible for these situations to cause conflict when you execute or compile some other programs which are somewhat related to the current using formula or program.
精彩评论