読者です 読者をやめる 読者になる 読者になる

<Mac> パッケージ管理ツール「Homebrew」を入れる

やりたいこと

  • App Storeにないパッケージもインストールしたい
  • ローカル環境をなるべく汚したくない(任意の場所にインストールしたい)
  • 依存関係を自動的に解決してほしい
  • 自分の環境に最適化させたいときはビルドもしたい

Homebrewの特徴

MacportsFinkなどでもできるようですが、今回はHomebrewを使います。
cf) Homebrew — macOS 用パッケージマネージャー

インストール方法

XcodeとCommand Line Tools for Xcodeが必要です。

Xcode

App Storeから「Xcode」で検索してインストールします。
Xcodeのバージョンを確認します。

$ xcodebuild -version
Xcode 8.1
Build version 8B62

Command Line Tools for Xcode

以下にアクセスして、OSのバージョンにあったものを入手してインストールしてください。Apple IDが必要です。私の場合は、macOS Sierra(バージョン10.12.1)だったので、「Command Line Tools (macOS 10.12) for Xcode 8.1」をインストールしました。

https://developer.apple.com/downloads/index.action

Command Line Toolsのバージョンを確認します。

$ pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
package-id: com.apple.pkg.CLTools_Executables
version: 8.1.0.0.1.1476494586
volume: /
location: /
install-time: 1478539344
groups: com.apple.FindSystemFiles.pkg-group 

Homebrew

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew
==> The following new directories will be created:
/usr/local/Cellar
/usr/local/Homebrew
/usr/local/Frameworks
/usr/local/bin
/usr/local/etc
/usr/local/include
/usr/local/lib
/usr/local/opt
/usr/local/sbin
/usr/local/share
/usr/local/share/zsh
/usr/local/share/zsh/site-functions
/usr/local/var

Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/mkdir -p /usr/local/Cellar /usr/local/Homebrew /usr/local/Frameworks /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/opt /usr/local/sbin /usr/local/share /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var
Password:
==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/Cellar /usr/local/Homebrew /usr/local/Frameworks /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/opt /usr/local/sbin /usr/local/share /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var
==> /usr/bin/sudo /bin/chmod 755 /usr/local/share/zsh /usr/local/share/zsh/site-functions
==> /usr/bin/sudo /usr/sbin/chown yamadatakaaki /usr/local/Cellar /usr/local/Homebrew /usr/local/Frameworks /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/opt /usr/local/sbin /usr/local/share /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var
==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/Cellar /usr/local/Homebrew /usr/local/Frameworks /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/opt /usr/local/sbin /usr/local/share /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var
==> /usr/bin/sudo /bin/mkdir -p /Users/yamadatakaaki/Library/Caches/Homebrew
==> /usr/bin/sudo /bin/chmod g+rwx /Users/yamadatakaaki/Library/Caches/Homebrew
==> /usr/bin/sudo /usr/sbin/chown yamadatakaaki /Users/yamadatakaaki/Library/Caches/Homebrew
==> Downloading and installing Homebrew...
HEAD is now at 42bb0f8 Merge pull request #1453 from ddbeck/revise-troubleshooting
==> Homebrew has enabled anonymous aggregate user behaviour analytics
Read the analytics documentation (and how to opt-out) here:
  https://git.io/brew-analytics
==> Tapping homebrew/core
Tapped 3627 formulae (3,775 files, 9.3M)
Already up-to-date.
==> Installation successful!
==> Next steps
Run `brew help` to get started
Further documentation: https://git.io/brew-docs

正常にインストールされたことを確認します。

$ brew doctor
Your system is ready to brew.

設定を調べてみます。

$ brew --config
HOMEBREW_VERSION: 1.1.0
ORIGIN: https://github.com/Homebrew/brew
HEAD: b7abd33475b98598b414f9c4ee2e20249855437b
Last commit: 24 hours ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 347ff4c58b374b7bc641838067772d2a87c1506d
Core tap last commit: 37 minutes ago
HOMEBREW_PREFIX: /usr/local
HOMEBREW_REPOSITORY: /usr/local/Homebrew
HOMEBREW_CELLAR: /usr/local/Cellar
HOMEBREW_BOTTLE_DOMAIN: https://homebrew.bintray.com
CPU: octa-core 64-bit haswell
Homebrew Ruby: 2.0.0-p648
Clang: 8.0 build 800
Git: 2.9.3 => /Applications/Xcode.app/Contents/Developer/usr/bin/git
Perl: /usr/bin/perl
Python: /usr/bin/python
Ruby: /usr/bin/ruby => /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
Java: N/A
macOS: 10.12.1-x86_64
Xcode: 8.1
CLT: 8.1.0.0.1.1476494586
X11: N/A