117

When I run brew doctor I get the common warning:

Warning: You have unlinked kegs in your Cellar
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
# [...]

What does it mean for kegs to be unlinked? And what does brew link do exactly?

1

2 Answers 2

67

Homebrew can allow multiple versions of a formula to be installed. For example, there is formulae called node and node@10 and similar.

$ brew info node@10
...
==> Caveats
node@10 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If I have both node and node@10 installed, where node is at v11. I can decide later to active the earlier version with brew link:

$ brew unlink node

$ brew link node@10

$ cd /urs/local/bin
$ ls -l node
lrwxr-xr-x  1 user  admin  34 12 Dec 20:07 node -> ../Cellar/node@10/10.14.1/bin/node

Here the symlink node is pointing to an earlier version (keg-only) installed in Cellar.

3
  • 2
    brew link --force --overwrite node@10
    – Zhang Buzz
    Mar 10, 2020 at 8:35
  • @themefield Hi, I had tried this with gcc@9with gccalready installed but brew info gcc@9 did not return the => Caveats about keg only that you mentioned above. I was wondering if you knew how to tell the system to use the older gcc v9 in this case?
    – CAF
    Mar 13, 2021 at 15:57
  • use command: ls -lh /usr/local/opt to see the list of possible links (parameters options for brew unlink & link) May 3 at 9:31
55

brew link creates symlinks to installations you performed manually in Cellar. This allows you to have the flexibility to install things on your own but still have those participate as dependencies in homebrew formulas.

See the FAQ for more information.

You should follow those instructions and run brew link on the entries it lists.

2
  • 24
    I was after a more low-level answer: Where do these symlinks reside? What/where is the Cellar? If you clarify with this information I would like to accept this answer.
    – mbaytas
    Nov 3, 2016 at 13:55
  • 4
    The symlinks can be seen with ls as normal links. ls -lh /usr/local/bin/python => /usr/local/bin/python -> ../Cellar/python/3.6.4_3/bin/python. For a complete reference of all the symlinks homebrew manages I am curious too. Cellar is simply where all the Homebrew packages reside. It is under /usr/local/Cellar. Mar 12, 2018 at 17:02

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.