3
votes

After running

brew install yarn

I have the below version of node installed on my system:

$ node -v
v10.5.0

because node is a dependency of yarn (correct me if I'm wrong, please tell me if I'm right too)

But it causes problem with yarn (the problem I face is this) so I want to use an older version of node to make my app work now. According to this, I did these:

$ brew install node@8
$ brew unlink node
$ brew link node@8

But $ brew link node@8 gives me the following:

Warning: node@8 is keg-only and must be linked with --force
Note that doing so can interfere with building software.

If you need to have this software first in your PATH instead consider running:
  echo 'export PATH="/usr/local/opt/node@8/bin:$PATH"' >> ~/.zshrc

I used rvm, ruby can be switch by simply using rvm use ruby-version-here so I think brew link formula will work, but why it needs force?

I understand that brew's keg-only means it's only in cellar and not linked in /usr/local/bin/ or /usr/local/lib/, but isn't brew link helping us link it, why does it need the --force option, what does it do, it feels dangerous.

brew help link says:

If --force (or -f) is passed, Homebrew will allow keg-only formulae to be linked.

Why should we be careful to link them? Will we break something?

I want to use node@8 instead of node (the latest version), what is the correct way to do this? Do I just run with the force option as suggested by brew?

Update 1: When I keep searching and finding out why, I saw this, but I don't understand it fully. It seems like it needs to delete some file when linking to new version of formula. But I thought linking will be just replacing the link somewhere, maybe just replace one file? Why create a specific --force option for linking to new keg-only formula? I suspect there is something special about keg-only formula's nature. Does anyone understand why?

Note: This and this explains what keg-only means

1

1 Answers

3
votes

First, yes node is a dependency of yarn, you can check it with:

brew deps yarn

Then the --force option is maybe not so well named but it does what is said in the man page:

If --force (or -f) is passed, Homebrew will allow keg-only formulae to be linked.

This is just the way Homebrew works, there is no fear to have.

== EDIT

In previous version of Homebrew the documentation was much clearer:

If --force is passed, Homebrew will delete files which already exist in the prefix while linking.

If --dry-run or -n is passed, Homebrew will list all files which would be deleted by brew link --force, but will not actually link or delete any files.

== EDIT (2)

Here is the discussion that precedes the introduction of the --force parameter to allow linking keg-only formula. The reasons behind it is that installing keg-only formula system wide could interfere with other tools that expect some specific versions of standard programs.