YCode
YCode

Reputation: 1272

How to fix Brew's symlink errors when Brew thinks the link already exists?

Please help understand what is going on--or whether any action is required. I've gone through a lot of posts on dealing with brew, node, symlink, uninstalled and reinstalled node, npm, yarn, tried brew cleanup. When brew doctor produced these warnings--

 Warning: Broken symlinks were found. Remove them with `brew prune`:
      /usr/local/lib/node_modules/npm/node_modules/.bin/JSONStream
      /usr/local/lib/node_modules/npm/node_modules/.bin/errno
      /usr/local/lib/node_modules/npm/node_modules/.bin/is-ci
      /usr/local/lib/node_modules/npm/node_modules/.bin/node-gyp
      /usr/local/lib/node_modules/npm/node_modules/.bin/opener
      /usr/local/lib/node_modules/npm/node_modules/.bin/qrcode-terminal
      /usr/local/lib/node_modules/npm/node_modules/.bin/rc
      /usr/local/lib/node_modules/npm/node_modules/.bin/semver
      /usr/local/lib/node_modules/npm/node_modules/.bin/sshpk-conv
      /usr/local/lib/node_modules/npm/node_modules/.bin/sshpk-sign
      /usr/local/lib/node_modules/npm/node_modules/.bin/sshpk-verify
      /usr/local/lib/node_modules/npm/node_modules/.bin/uuid
      /usr/local/lib/node_modules/npm/node_modules/.bin/which

When I tried brew prune, I got:

newmbp$ brew link node
Warning: Already linked: /usr/local/Cellar/node/10.11.0

I noticed the files (to be linked or unlinked) are in separate folders, but have been struggling to understand the implications of having files in /usr/local/Cellar vs in /usr/local/lib

The precipitating factor that led to all of this was the fan on my laptop runs furiously from time to time, often while MAMP is running.

Upvotes: 3

Views: 13484

Answers (1)

bfontaine
bfontaine

Reputation: 19860

brew cleanup --prune-prefix (ex- brew prune) removed the broken symlinks, so the issue should be gone.

The fact that brew link node complains has nothing to do with this; it’s a completely different command. It’s not even an error, just a warning: "you asked me to link node but it’s already linked" so everything’s fine here.


Homebrew installs its files in /usr/local/Cellar. On the other hand, /usr/local/lib is a shared directory commonly used for libraries. In order for software to find libs Homebrew installed, it symlinks them in it.

For example, let’s say you have a formula foo version 1.2.3 that installs a library bar. After running brew install foo you should get something like this:

# the library files
/usr/local/Cellar/foo/1.2.3/lib/bar
# a symlink to the library files from /usr/local/lib
/usr/local/lib/bar -> /usr/local/Cellar/foo/1.2.3/lib/bar

If you brew uninstall foo, it removes both the library files and the symlink.

Those Homebrew symlinks can be manipulated with brew unlink <formula> (remove them) and brew link <formula> (add them). brew install runs brew link for you so you don’t need to. This is the reason why you get a warning: your Node symlinks already exist.

brew doctor performs various checks, including check_for_broken_symlinks. This one looks into directories such as /usr/local/var or /usr/local/lib for broken symlinks. A broken symlink is a symlink whose target doesn’t exist, often because it has been removed.

The important point to understand here is that Homebrew looks at all symlinks, not just the ones it created. Broken symlinks may cause issues, which is why Homebrew warns you about them, but if everything’s working fine for you feel free to ignore the warning.

Upvotes: 9

Related Questions