ろむめも

気になったこととか、調べたことをゆるくまとめます。主にプログラミング関連の話題が多いです。

Mac環境にHomebrew経由でパッケージをインストールする

経緯

mac環境にGoogle ProtocolをHomebrewでインストールしようとした時の話です。
後で別の記事に書きますが、もともとはCaffeをインストールしたかったのですが、
その過程で、後述の通りグーグルプロトコルのインストールを行いました。
他のパッケージもこれと同じようにインストールできます

やった事

久しぶりにHomebrewを立ち上げたのでまずは環境の検証から。

brew doctor

すると

Warning: Your Homebrew is outdated.
You haven't updated for at least 24 hours, this is a long time in brewland!
To update Homebrew, run `brew update`.

バージョンが古いということなので

brew update

でアップデート実行。

ところが、

error: unable to unlink old '.gitignore' (Permission denied)
error: unable to create file .travis.yml (Permission denied)
error: unable to create file .yardopts (Permission denied)
error: unable to unlink old 'CODEOFCONDUCT.md' (Permission denied)
error: unable to unlink old 'CONTRIBUTING.md' (Permission denied)
error: unable to unlink old 'LICENSE.txt' (Permission denied)
error: unable to unlink old 'README.md' (Permission denied)
error: unable to unlink old 'SUPPORTERS.md' (Permission denied)
Error: Failure while executing: git pull -q origin refs/heads/master:refs/remotes/origin/master

と表示されアップデートできませんでした。

homebrewのupdateが失敗した時 - まめ畑
の記事を発見し、書かれているように実行

cd `brew --prefix`
git remote add origin https://github.com/mxcl/homebrew.git
fatal: remote origin already exists.
git fetch origin
remote: Counting objects: 10, done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 10 (delta 4), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (10/10), done.
From https://github.com/Homebrew/homebrew
   ed46a0a..1e6d9b9  master     -> origin/master
git reset --hard origin/master
warning: unable to unlink Library/ENV/pkgconfig/10.9: Operation not permitted
error: unable to unlink old '.gitignore' (Permission denied)
error: unable to create file .travis.yml (Permission denied)
error: unable to create file .yardopts (Permission denied)
error: unable to unlink old 'CODEOFCONDUCT.md' (Permission denied)
error: unable to unlink old 'CONTRIBUTING.md' (Permission denied)
error: unable to unlink old 'LICENSE.txt' (Permission denied)
error: unable to unlink old 'README.md' (Permission denied)
error: unable to unlink old 'SUPPORTERS.md' (Permission denied)
fatal: Could not reset index file to revision 'origin/master'.
brew update
Error: The /usr/local directory is not writable.
Even if this directory was writable when you installed Homebrew, other
software may change permissions on this directory. Some versions of the
"InstantOn" component of Airfoil or running Cocktail cleanup/optimizations
are known to do this.

You should probably change the ownership and permissions of /usr/local
back to your user account.
  sudo chown -R $(whoami):admin /usr/local

これでもダメのようでしたが、よく読むとpermissionの問題を指摘されていました。

そこで、ログインしているアカウントにアクセス件を与えて、

sudo chown -R $(whoami):admin /user/local
chown: /user/local: No such file or directory
sudo chown -R $(whoami):admin /usr/local

これでホームブリューのアップデートが

brew update
Updated Homebrew from 3dcf8b5d to b961ec13.

成功しました。

最後に

brew install protobuf

Google ProtocolBufferのインストールが完了しました

試しに実行

protoc
Missing input file.

ちゃんとprotocはいますね。

以上です。