[macOS] Homebrew をインストール(ついでにGitもインストール)
macOS のパッケージ管理ツール Homebrew をインストールする方法をご紹介します。
(最終更新日:2020年4月9日)
・公式:Homebrew — MacPorts driving you to drink? Try Homebrew!
homebrewは、system に元から入っている環境をそのまま使うので、序盤の環境構築をサクサクできるというのがポイントみたいです。
Homebrew インストール
HomebrewのインストールをGitHubからRubyスクリプトで行います。
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
インストールが完了したら、brew doctor を実行します。
$ brew doctor Error: Experimental support for using Xcode without the "Command Line Tools". |
Command Line Tools をインストールしろと言われるので、
Xcodeのメニュー
Xcode->Open Developer tool -> More Developer tool
をクリックして、ジャンプ先から Command Line Tool for Xcodeをダウンロードする。
ダウンロードして、通常のアプリケーションと同じようにインストール。
再度、brew doctor を実行。
$ brew doctor Your system is ready to brew. |
OK!
Homebrew自体Gitを使っているので、まずGitをインストールします。
インストール後、すぐにupdateします。
$ brew install git $ brew update $ brew -v 0.9.4 |
以上です。
========
もし、brew install git がエラーで失敗する場合は、kernel.orgのサイトが利用できないのが原因ということがあります。
(今回は kernel.org がメンテナンス中で使えませんでした。)
この場合、Formula内の git.rb を編集して、ダウンロード先のURLを書き換える必要があります。
$ vim /usr/local/Library/Formula/git.rb |
デフォルトでは、以下のようになっているのを、
class GitManuals < Formula url 'http://kernel.org/pub/software/scm/git/git-manpages-1.7.6.1.tar.bz2' md5 'cae559424a62507cb2c15252d85a158e' end class GitHtmldocs < Formula url 'http://kernel.org/pub/software/scm/git/git-htmldocs-1.7.6.1.tar.bz2' md5 'f698e0abbf1555582e30320930391c59' end class Git < Formula url 'http://kernel.org/pub/software/scm/git/git-1.7.6.1.tar.bz2' md5 'd1e00772cc9dc6c571999feb9e8771ab' |
以下のように書き換えます。
class GitManuals < Formula url 'http://ftp.uk.freesbie.org/sites/ftp.kernel.org/pub/software/scm/git-core/git-manpages-1.7.6.1.tar.bz2' md5 'cae559424a62507cb2c15252d85a158e' end class GitHtmldocs < Formula url 'http://ftp.ntu.edu.tw/ftp/pub2/software/scm/git/git-htmldocs-1.7.6.1.tar.bz2' md5 'f698e0abbf1555582e30320930391c59' end class Git < Formula url 'https://github.com/git/git/tarball/v1.7.6.1' md5 'ab731cf9b99529f3f8d126aa15d9a1cd' |
今回のように、kernel.orgが落ちていたら、ミラーサイトのURLに書き換えましょう。
・Index of /pub/software/scm/git
・git関連のミラーサイト:Index of /ftp/pub2/software/scm/git/
・gitのミラーサイト:Downloads for git's git – GitHub
以上です。
参考情報
・初めてのHomebrewインストール. #install #環境構築 #homebrew – Qiita
・[homebrew]Homebrewインストールメモ | milligramme 3cc
・OS X LionのMacbookAirを買ってからRailsの開発環境整えるためにやったことメモ | 野ログはノロキュアMaxHeart