“brew link node” creates/removes different number of symlinks when repeated

homebrewsymlinkupgrade

I was upgrading Node.js node through Homebrew's brew upgrade, and it didn't link correctly.

$ brew update
(snip-snip formulae were updated)
$ brew upgrade
(snip-snip other upgrades)
==> Upgrading node
==> Downloading http://nodejs.org/dist/v0.8.11/node-v0.8.11.tar.gz

################################################################## 100.0%

==> ./configure –prefix=/usr/local/Cellar/node/0.8.11
==> make install
==> Caveats
Homebrew installed npm.
We recommend prepending the following path to your PATH environment
variable to have npm-installed binaries picked up:
/usr/local/share/npm/bin
Warning: Could not link node. Unlinking…
Error: The brew link step did not complete successfully
The formula built, but is not symlinked into /usr/local
You can try again using `brew link node'
==> Summary
/usr/local/Cellar/node/0.8.11: 856 files, 13M, built in 108 seconds
(snip-snip other upgrades)

I followed the recommended steps to force linking it.

$ brew link node
Linking /usr/local/Cellar/node/0… Warning: Could not link node. Unlinking…

Error: Could not symlink file: /usr/local/Cellar/node/0.8.11/lib/node_modules/npm/scripts/relocate.sh
Target /usr/local/lib/node_modules/npm/scripts/relocate.sh already exists. You may need to delete it.
To force the link and delete this file, do:
brew link -f formula_name

To list all files that would be deleted:
brew link -n formula_name
$ brew link -f node
Linking /usr/local/Cellar/node/0.8.11… 756 symlinks created

I was stunned with the number of symlinks, so out of curiosity I tried linking it again.

$ brew unlink node
Unlinking /usr/local/Cellar/node/0.8.11… 755 links removed
$ brew link node
Linking /usr/local/Cellar/node/0.8.11… 352 symlinks created
$ brew link node
Warning: Already linked: /usr/local/Cellar/node/0.8.11
$ which node
/usr/local/bin/node
$ brew unlink node
Unlinking /usr/local/Cellar/node/0.8.11… 351 links removed
$ brew link node
Linking /usr/local/Cellar/node/0.8.11… 304 symlinks created
$ brew unlink node
Unlinking /usr/local/Cellar/node/0.8.11… 303 links removed
$ brew link node
Linking /usr/local/Cellar/node/0.8.11… 304 symlinks created
$ brew unlink node
Unlinking /usr/local/Cellar/node/0.8.11… 303 links removed

The process stabilizes at 304/303.

  1. Why so many symlinks?
  2. Why does the link/unlink number change from 756 to 303?

Edit: ran the same update/upgrade/link/unlink procedure on a colleague's computer – in this case the symlinks went from 775 to 318 to 226, where it stabilized. Does anyone else have similar numbers? Do they depend on other installed brew recipes, or perhaps on npm modules?

Best Answer

Do you have several versions of Node installed via homebrew? Every time it updates node homebrew puts the newest version alongside the old one and then updates the symlinks to the newest version. Running the brew cleanup should reduce that up a bit for you.