#はじめに
##目的
Sierraの乗った2011年のMacBook Proに
パッケージマネージャHomebrewを導入し、動作確認までをします。
##環境
- MacBook Pro Late2011
- MacOS Sierra(version10.12.3)
- xcode 8.2.1
#導入
##ダウンロードとインストール
下記リンク先にあるインストール用コマンドを実行します。
HomeBrew公式ページ
インストールコマンド実行後、下のような出力を得ました。
Xcodeのライセンスに同意していないのでHomebrew実行前に同意するように求められます。
You have not agreed to the Xcode license.
Before running the installer again please agree to the license by opening
Xcode.app or running:
sudo xcodebuild -license
指示に従いライセンス同意のためのコマンドを実行しました。
下の出力に同意するためにagreeを入力します。
$ sudo xcodebuild -license
...
By typing 'agree' you are agreeing to the terms of the software license agreements. Type 'print' to print them or anything else to cancel, [agree, print, cancel]
-vオプションでバージョンを出力させ、
インストールできているかをかんたんに確認できました。
$ brew -v
Homebrew 0.9.9 (git revision 2044; last commit 2016-05-12)
Homebrew/homebrew-core (git revision 50af; last commit 2016-05-12)
##エラーチェック
Homebrew doctorでhomebrewのエラーチェックをおこないます。
いくつかwarningが出てきました。
それぞれ解決していきます。
$ brew doctor
warning: /usr/local is not writable.
You should probably change the ownership and permissions of /usr/local
back to your user account.
sudo chown -R $(whoami) /usr/local
chown -Rで/usr/local以下の所有権をかえるように求められました。
usr/local以下の所有権はhomebrewを実行するユーザにしたら良いようです。
(whoamiは現在実行中のユーザを出力するコマンド)
$ sudo chown -R $(whoami) /usr/local/
If you didnt put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected dylibs:
/usr/local/lib/libcdt.5.dylib
/usr/local/lib/libcgraph.6.dylib
/usr/local/lib/libgvc.6.dylib
/usr/local/lib/libgvpr.2.dylib
/usr/local/lib/libpathplan.4.dylib
/usr/local/lib/libtcl8.6.dylib
/usr/local/lib/libtk8.6.dylib
/usr/local/lib/libxdot.4.dylib
目的なく以下のdylibを置いてるなら削除した方が良いかもしれない、問題を起こすことがある、
とwarningが出ています。
消さなくても問題がないみたいなのでとりあえず放っておきます。
問題が起これば対処します。
同じ種類のwarningが
- headerファイル (/usr/local/include)
- pcファイル (/usr/local/lib/pkgconfig)
- staticライブラリ(/usr/local/lib)
にも出ていますがこちらも問題起こるまで放置することにします。
Warning: You are using OS X 10.12.
We do not provide support for this pre-release version.
You may encounter build failures or other breakages.
まだhomebrewが最新版でないために出ました。
homebrewをアップデートします。
$ brew update
/usr/local/Library/Homebrew/cmd/update.sh: line 15: /usr/local/Library/ENV/scm/git: No such file or directory
Error: update-report should not be called directly!
直接アップデートレポを呼ぶな、と出ます。
エラーの意味はよくわからないですが調べたところ、
upgradeしてからupdateすると良いとのこと。
(そのうち原因を調べます)
$ brew upgrade
...
==> Migrating HOMEBREW_REPOSITORY (please wait)...
Error: /usr/local/Homebrew already exists.
Please remove it manually or uninstall and reinstall Homebrew into a new
location as the migration cannot be done automatically.
...
どうやら以前に一度中途半端に導入を試みたことがあったようです。
不要なHomrbrewディレクトリ以下を再帰的に削除します。
$ rm -r /usr/local/Homebrew
アップグレードとアップデートをやり直します。
$ brew upgrade
$ brew update
Already up-to-date.
アップデートしたのでバージョンを確認しました。
$ brew -v
Homebrew 1.1.10-335-g417afc2
Homebrew/homebrew-core (git revision aa8e6; last commit 2017-02-26)
2017/02/27現在の最新版にアップデートされました。
doctorに吐かれたwarning対処に戻ります。
Warning: Broken symlinks were found. Remove them with `brew prune`:
/usr/local/share/ghostscript/9.16/Resource/CIDFSubst/Kaiti.ttc
/usr/local/share/ghostscript/9.16/Resource/CIDFSubst/Klee.ttc
/usr/local/share/ghostscript/9.16/Resource/CIDFSubst/LiHeiPro.ttf
/usr/local/share/ghostscript/9.16/Resource/CIDFSubst/LiSongPro.ttf
/usr/local/share/ghostscript/9.16/Resource/CIDFSubst/NanumGothic.ttc
/usr/local/share/ghostscript/9.16/Resource/CIDFSubst/NanumMyeongjo.ttc
/usr/local/share/ghostscript/9.16/Resource/CIDFSubst/NanumScript.ttc
/usr/local/share/ghostscript/9.16/Resource/CIDFSubst/STFangsong.ttf
/usr/local/share/ghostscript/9.16/Resource/CIDFSubst/STHeiti.ttf
/usr/local/share/ghostscript/9.16/Resource/CIDFSubst/STXihei.ttf
...
#全部で31個のリンク切れがありました。
シンボリックリンク切れです。
指示に従い削除します。
$ brew prune
Pruned 31 symbolic links from /usr/local
最後のwarningです。
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`.
先ほど最新版にしたので無視します。
24時間更新しないだけで最新でないと判断するようです。
一通りのwarningへの対処を終えたので再びdoctorで状態を確認します。
”doctorで吐かれたwarning(2)”のあえて放置したwarning以外は全て消えていました。
##動作確認
インストールしてwarningも消したので、実際に使って確かめてみます。
gnuplotを使う予定があるため、gnuplotのインストールをおこないます。
gnuplotはOSSのグラフ作成アプリケーションです。
$ brew install gnuplot --with-x11
...
🍺 /usr/local/Cellar/gnuplot/5.0.5_2: 47 files, 2.5M, built in 3 minutes 37 seconds
--withオプションでX11を指定しています。
homebrewでgnuplotをインストールするときには出力先を指定する必要があるためです。
X11以外にも、AquaTermも使えるようです。
事前にXQuortz最新版をインストールしておきます。
また、gnuplotでグラフ描画をする前に、X11は起動しておかなければなりません。
gnuplotを起動し、sin(x)のグラフを描画します。
gnuplotが正しくインストールされたことを確認します。
$ gnuplot
G N U P L O T
Version 5.0 patchlevel 5 last modified 2016-10-02
Copyright (C) 1986-1993, 1998, 2004, 2007-2016
Thomas Williams, Colin Kelley and many others
gnuplot home: http://www.gnuplot.info
faq, bugs, etc: type "help FAQ"
immediate help: type "help" (plot window: hit 'h')
Terminal type set to 'x11'
最新のバージョン5.0であることと、X11が出力先に設定されていることが確認できます。
gnuplot> plot sin(x)
無事sin(x)のグラフが出力されました。
#まとめ
##やったこと
- homebrewを一度中途半端にインストールした状態から正しくインストール
- gnuplotを用いた動作確認
##わかったこと
- 公式ページのインストール手順に従っても最初は最新版が手に入らない
- アナロジー的発想で、パッケージマネージをビール醸造に例えている
多くの内容がすでにインターネット上にどなたかにより公開されているものです。
この記事の新しいところは”Homebrewが一度中途半端に導入されていてローカルリポジトリが残っている場合の対処法”が書かれているところです。
この対処法が記された日本語記事は簡単に探した範囲では見つかりませんでした。
どなたかの参考になれば幸いです。
#参考にした記事
今回は多くの記事を参考にさせていただきました。ありがとうございました。
Homebrewのコマンドと使い方まとめ
http://www.task-notes.com/entry/20140706/1404619443
HomeBrewの仕組みについてまとめておく
http://takuya-1st.hatenablog.jp/entry/20111224/1324750111
Homebrewをインストールしてみた。が、brew doctorでWarningが出てしまった。
http://yasutaka-hirai.hatenablog.com/entry/2016/03/07/213520
gnuplotをHomebrewからインストールするときの手順
http://qiita.com/noanoa07/items/a20dccff0902947d3e0c