2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

brew caskで欲しいバージョンのfomulaがないのでtap自作する

Last updated at Posted at 2019-12-27

Virtualboxの5.2をインストールしたいのですが、2019-12-27現在 brew install virtualbox すると 6.1がインストールされてしまいます。
tapを自作して解決しましょう。

1. 公式のCask Codeを参照する

https://formulae.brew.sh/cask/virtualbox
https://github.com/Homebrew/homebrew-cask/blob/master/Casks/virtualbox.rb

2. Tapリポジトリを公開する

やり方はこちらを参考にしました。
https://qiita.com/tarappo/items/8d6cb62be3b91f0be583

dmgファイルのダウンロードURLを公式サイトから控え、バイナリの SHA256を算出した後、公式のCask Codeをコピペして置換した結果がこちらです。
https://github.com/hiroga-cc/homebrew-virtualbox-5.2

ハマりどころ

image.png

ルートディレクトリに .rbファイルを作成するのではなく、 プロジェクトルート/Casks/***.rb の構成で作る必要があります。
誤ってルートディレクトリに作成した場合は以下のエラーが発生し、私は原因特定まで1時間を費やしました...。

$ brew tap hiroga-cc/virtualbox-5.2
==> Tapping hiroga-cc/virtualbox-5.2
Cloning into '/usr/local/Homebrew/Library/Taps/hiroga-cc/homebrew-virtualbox-5.2'...
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 4 (delta 0), pack-reused 0
Receiving objects: 100% (4/4), done.
Error: Invalid formula: /usr/local/Homebrew/Library/Taps/hiroga-cc/homebrew-virtualbox/virtualbox-5.2.rb
virtualbox: undefined method `cask' for Formulary::FormulaNamespacead380ff8d454670d2504ca62549826bd:Module
Error: Cannot tap hiroga-cc/virtualbox: invalid syntax in tap!

(Ruby分かる人だと即解決できたりするんですかね?)

3. インストールする

brew tap hiroga-cc/virtualbox-5.2
brew cask install virtualbox-5.2

image.png
やったぜ!完了。

2
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?