【開発】os x el capitanでbrew updateする
macで開発している人で、既にel capitanを使っている人は少なくないと思います。ただel capitanでは「System Integrity Protection」というセキュリティ機能が追加されたため、開発する時には注意が必要です。
そこでこの記事は、os xのパッケージ管理システムの一つ「Homebrew」をうまく動作させるためにやることをまとめます。
現象
DBにpostgreSQLを使ったプロジェクトをローカルで動かしたいと思い、brew install postgreSQL
でpostgreSQLをインストールしようとしたところ、以下のようなエラーが。
(略) ==> Installing postgresql dependency: openssl ==> Downloading https://www.openssl.org/source/openssl-1.0.2a.tar.gz curl: (22) The requested URL returned error: 404 Not Found Trying a mirror... ==> Downloading https://raw.githubusercontent.com/DomT4/LibreMirror/master/OpenSSL/openssl-1.0.2a.tar.gz curl: (22) The requested URL returned error: 404 Not Found Error: Failed to download resource "openssl" Download failed: https://raw.githubusercontent.com/DomT4/LibreMirror/master/OpenSSL/openssl-1.0.2a.tar.gz
ネットでいろいろ調べているとbrew update
すると解決するって書かれていたので実行するも、
error: unable to unlink old '.gitignore' (Permission denied) error: unable to create file .travis.yml (Permission denied) error: unable to unlink old '.yardopts' (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
といった感じで怒られました。
原因
どうやらos xにアップグレードするときに/usr/local
のパーミッションが変わってしまったらしいです。
解決策
まずはusr/local
の所有者を変更します。
chown user_name:admin /usr/local && sudo chown -R user_name:admin /usr/local
これでbrew update
してみましたが次のようなエラーが出ました。
(略) Library/Homebrew/utils/git.rb already exists, no checkout Could not restore untracked files from stash
よくわからないのですがどうやらgitがおかしいようです。 公式サイトを参考に以下のコマンドを実行します。
cd $(brew --prefix) && git fetch && git reset --hard origin/master
今度はちゃんとbrew update
できるようになりました。
同じようなエラーが出る人がいたらこれをやってみるといいかもしれません。