かすみん日記

暇なときに何か喋ります

【homebrew】Warning: You have unlinked kegs in your Cellar.

brew doctor したら brew link node しろと怒られるが、それができない。

前提

  • 公式サイトからNode.jsをインストールした
  • brewでも node をインストールしている(yarn の依存パッケージとして)
  • nodenodebrew で管理したい(している)

結論

  1. pkgでインストールした node.js を削除
  2. brew uninstall node
  3. npm install --global yarn

症状と挑戦

brew doctor

お医者さんによると以下のような感じ;

% brew doctor

略
Warning: Unbrewed header files were found in /usr/local/include.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected header files:
  /usr/local/include/node/略/略.h
  略(大量)

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

brew link

brew link node をしてもパーミションエラー;

% brew link node
Linking /usr/local/Cellar/node/15.9.0... 
Error: Could not symlink include/node/common.gypi
/usr/local/include/node is not writable.

brew unlink node はエラーは出ないがなんの効果もない。

brew reinstall node

brew管理のnodeを再インストールしてみる;

% brew reinstall node
略
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink include/node/common.gypi
/usr/local/include/node is not writable.

You can try again using:
  brew link node
Warning: The post-install step did not complete successfully
You can try again using:
  brew postinstall node
==> Summary
🍺  /usr/local/Cellar/node/15.9.0: 3,390 files, 56.1MB

brew postinstall

じゃあということでポストインストールしてみる;

 % brew postinstall node
==> Postinstalling node
Warning: The post-install step did not complete successfully
You can try again using:
  brew postinstall node

sudo brew

sudo をつけて brew linkbrew postinstall をしてもだめ。

pkgのnodeをアンインストール

以下の記事を参考に、公式サイトからインストールしたnodeを完全に削除してみる;

geniusium.hatenablog.com

pkgでインストールしたnodeを削除してもダメ。 でも、エラーメッセージが少し変わった;

% brew link node
Linking /usr/local/Cellar/node/15.9.0... 
Error: Could not symlink share/systemtap/tapset/node.stp
/usr/local/share/systemtap/tapset is not writable.

解決?

まあ、パーミッションエラーということなので、そのディレクトリに権限付与すればいいだけではある;

sudo chown -R $USER /usr/local/share/systemtap/tapset

すると、エラーは出ない;

% brew link node                                       
Linking /usr/local/Cellar/node/15.9.0... 7 symlinks created.

brew doctor でも該当の警告は消えた。

真の解決法

いや、なんで手動で権限与えなきゃあかんねん。

めんどい、というかどう考えてもbrewの不具合、バグ。

そもそも nodenodebrew で別に管理しているのに yarn のためにそれとは別に node をインストールしなきゃいけないのはおかしい。

yarn インストール時に node はインストールしないような設定があるが、バグでうまくいかないらしい。

yarn を普通にインストールしてから、依存関係無視して node だけアンインストールすればいいらしいが、いや、だからめんどいて。

そして導き出されるたった一つの真実とは、、、そもそも brewyarn をインストールするのをやめる!!!

はい;

brew uninstall yarn
brew uninstall node

これで brew doctor で該当の警告は消えます。

yarn のインストール

npm でインストール;

npm install --global yarn

確認;

% yarn -v
1.22.10

npm list -g でも確認できます。

おしまい。

brewはちょいちょい面倒なことが起こるのであまり過信してはいけない。

参考

classic.yarnpkg.com

これはよくないという方法;

qiita.com