Mac

いつの間にかbrew caskが使用できなくなっていた話

big surのコマンドラインでbrew caskがUnknown Commandでエラーになってしまう。

はじめに

試行錯誤が長くなったので先に結論だけ書いておきます。

以下の3点をチェックしてみてください。
※いずれにも当てはまらない場合は当方とは異なる事象かと思います…

①caskコマンドの使い方が変更になった

旧) $ brew cask install xxx

新) $ brew install xxx --cask

新しい環境で古いコマンド、古い環境で新しいコマンドを使用していたりしないでしょうか?

②brew updateができない

homebrewのリポジトリというかGitHubが、”shallow cloneをやめようぜ”、って流れらしく、今までshallow cloneしていた人(恐らくデフォルト)はフェッチし直さないといけないらしいです。
(この辺の背景はあまり自信ないですが…)

以下のコマンドを実行すれば解決するはずです。

$ git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow

※うちの環境では実行に約7分かかりました。

③CLT(CommandLineTools)のバージョン違い

brew installした際に、"Your CLT does not support macOS 11."、みたいなエラーが出ていませんか?

CLTのバージョン違いなのでCLTを再インストールすれば解消されるはずです。

$ sudo rm -rf /Library/Developer/CommandLineTools
$ sudo xcode-select --install


以下は試行錯誤の痕跡です。

本文という名のおまけ


久しぶりにbrewコマンドを使用したところ、brew caskが以下のエラーで通らなくなってしまいました。

Error: Unknown command: cask


以前は使用できていたはずなのに何故だろうと思い、色々見ていったところ、バージョンが以下のようになっていました。

mathkuro002:~ kuro$ brew –version
Homebrew 3.0.1
Homebrew/homebrew-core (git revision de1d; last commit 2020-07-30)
Homebrew/homebrew-cask (git revision 68eefe; last commit 2021-02-15)


何故か、brew本体が古いままだったのです。

なんだーこのせいかー、と安心してupdateを打ったのですが、

mathkuro002:~ kuro$ brew update
Error:
homebrew-core is a shallow clone.
To brew update, first run:
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch –unshallow
This command may take a few minutes to run due to the large size of the repository.
This restriction has been made on GitHub’s request because updating shallow
clones is an extremely expensive operation due to the tree layout and traffic of
Homebrew/homebrew-core and Homebrew/homebrew-cask. We don’t do this for you
automatically to avoid repeatedly performing an expensive unshallow operation in
CI systems (which should instead be fixed to not use shallow clones). Sorry for
the inconvenience!
mathkuro002:~ kuro$


updateがエラーになりました…まじかよ…

エラーメッセージを読み解いてみると、「shallow cloneはコストが高いから止めようぜ!」、って流れのようです。

GitHubからも年末に記事出ていました。
https://github.blog/2020-12-21-get-up-to-speed-with-partial-clone-and-shallow-clone/

大規模リポジトリで作業することがないので私はそもそもshallow cloneを意識したことなかったですね…

ま、そういうことらしいので、素直にコマンドを実行します。

$ git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow


※うちの環境では実行に約7分かかりました。

これで無事にbrew updateが通るようになりました。

バージョンも問題なさそうです◎

mathkuro002:~ kuro$ brew –version
Homebrew 3.0.1
Homebrew/homebrew-core (git revision 395ba; last commit 2021-02-15)
Homebrew/homebrew-cask (git revision 68eefe; last commit 2021-02-15)


で、再度 $ brew caskを実行したのですがやはり最初のエラー(Unkown Command)になってしまいます…


あ、もしかして、Updateの途中でエラーになったせいでcaskコマンドがdeleteだけされたのでは??

mathkuro002:~ kuro$ brew list
boost gettext libgeotiff netcdf python@3.8
cairo giflib libidn2 nodebrew qt
cfitsio glib libmpc nspr readline
cmake gmp libpng nss sqlite
epsilon hdf5 libpq numpy szip
expat icu4c libspatialite openblas unixodbc
fontconfig isl libtiff openjpeg webp
freetype jasper libtool openssl@1.1 wget
freexl jpeg libunistring pcre xerces-c
gcc json-c libxml2 pixman xz
gdal krb5 little-cms2 poppler zstd
gdbm libdap lzo popt
geos libffi mpfr proj
blackhole
mathkuro002:~ kuro$

あらあら、caskが行方不明になっていらっしゃる。

よーしcaskインストールするぞー $ brew install cask ぽちっ。

Error: Your CLT does not support macOS 11.
It is either outdated or was modified.
Please update your CLT or delete it if no updates are available.
Update them from Software Update in System Preferences or run:
softwareupdate –all –install –force

If that doesn’t show you any updates, run:
sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select –install

Alternatively, manually download them from:
https://developer.apple.com/download/more/.

Error: An exception occurred within a child process:
SystemExit: exit


…あー、なんか今日はダメなパターンの日みたいです。

ことごとくエラーを踏み抜いていきます。

ソフトウェアアップデートは最新版になっていて関係ないはずなので、CLTのバージョン違いが原因でしょうか?

エラーメッセージの指示に従ってCLTを再インストールしてみます。

$ sudo rm -rf /Library/Developer/CommandLineTools
$ sudo xcode-select --install


コマンドを実行すると、以下のウィンドウが表示されます。

xcode-select --installするとウインドウが表示されるのでインストールをクリックする

「インストール」をクリックすると1分ほどでインストールが完了しました。


こ、今度こそ、と思いコマンドを実行してみますが…

$ brew cask –help
Error: Unknown command: cask

全然ダメです…


もうhomebrew再インストールしてやろうかしらと思いながらネット記事を漁っていると、光明が!
https://qiita.com/luton-mr/items/83386f43c395ecec7736


caskの使い方が変わったらしいです…


も、もっと早く言ってや。(←たぶんエラーメッセージ見逃したんだろうな…)


これにて一件落着ということで、なんとかcaskでパッケージのインストールができました◎

mathkuro002:~ kuro$ brew install blackhole-16ch –cask
==> Downloading https://existential.audio/downloads/BlackHole16ch.v0.2.9.pkg
################################################################## 100.0%
==> Installing Cask blackhole-16ch
==> Running installer for blackhole-16ch; your password may be necessary.
Package installers may write to any location; options such as –appdir are ignored.
Password:
installer: Package name is BlackHole: Virtual Audio Driver 16ch v0.2.9
installer: Installing at base path /
installer: The install was successful.
???? blackhole-16ch was successfully installed!


エラーメッセージはちゃんと読もうね、っていう戒めになりました。

参考

https://weblabo.oscasierra.net/homebrew-1/
https://weblabo.oscasierra.net/homebrew-uninstall/
https://qiita.com/luton-mr/items/83386f43c395ecec7736

コメント

  1. cask部分でエラーが発生していたので助かりました。

タイトルとURLをコピーしました