LoginSignup
19
21

More than 5 years have passed since last update.

macOS Mojave で Git を Homebrew 管理下に変更したときの顛末

Last updated at Posted at 2018-10-07

ことの始まり

「ダークモードが目に優しそうやし, Mojave使ってみたい! (今のとこ,不具合報告少ないし...)
あとHomebrewも入れて, いろんなツールのバージョン管理も楽にしたい!
ただmacOSのアップデートしたらHomebrewがうまく動かん記事もちらほらあるから, どうせ入れるならOSアップデートしてから入れよか〜.」

ということで, Mojaveデビューしました. 今のとこ致命的な不具合は発見できていません.

「よしOSアップデートもうまくいったし, 次はHomebrew入れて手始めにGitをbrewで扱ってみよか!」

このGitをHomebrewでインストールした結果が事前に調べていた内容と違っていたので, 解決までの顛末をログします.

動作環境

PC : MacBook Pro (15-inch, 2016)

OSアップデート前

  • macOS Sierra v10.12.6
  • git v2.14.3 (Apple Git-98)

OSアップデート直後

  • macOS Mojave v10.14
  • git v2.17.1 (Apple Git-112) ← OSアップデートと共に自動的にバージョンアップした

本記事の最終環境

  • macOS Mojave v10.14
  • Xcode v10.0 (10A255)
  • Homebrew v1.7.6
    • git v2.19.1
    • gettext (GNU gettext-runtime) v0.19.8.1
    • pcre2 v10.32

ここから本題

まずOSアップデート後に行った作業を時系列に示します.
1. Xcodeをインストール
2. Homebrewをインストール
3. Gitをインストール ← 雲行き怪しい
4. Gitのパスを通す ← なんとか解決


2018/10/12 追記
Homebrewのパッケージインストール方法の詳細手順を別記事にしました.
Homebrew パッケージインストール 詳細手順 - Qiita


Xcodeをインストール

Homebrewの利用にはXcode Command Line Toolsのインストールが必要です.
iOSアプリ開発に興味があるので, この機会にXcodeもApp Storeからインストールしました.1
因みに,Homebrewの利用のみが目的であれば,Xcodeをストアからインストールする必要はありません.
Homebrewのインストール時にダイアログが開くので, そこからCommand Line Toolsのみインストールできます.

Homebrewをインストール

ターミナル.appを開き, 次のリンク(Homebrew公式サイト)のインストール用コマンドをコピペしてEnter.

Homebrew — macOS 用パッケージマネージャー
本記事執筆時点のスクリプト(インストール用コマンド)
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

途中, ログインパスワードの入力を求められるので入力してEnter.
Xcode Command Line Toolsをインストールしていなければここでダイアログボックスが開くはずですので, そこからインストールをクリックしてください.
インストールが完了したら次のコマンドを叩いて内容を確認します.

ターミナル.app
$ which brew #Homebrewのインストール先ディレクトリを表示
/usr/local/bin/brew #このディレクトリが表示されれば正常

$ brew --version #現在のHomebrewバージョンを表示
Homebrew 1.7.6 #バージョン情報

Gitをインストール

次にHomebrewでGitをインストールしますが, インストールの前に次のコマンドを叩いて状況を確認しておきます.

ターミナル.app
$ which git #gitコマンドの実行ファイルがどこに格納されているのか表示
/usr/bin/git #現在のgitコマンドが置かれたディレクトリ

$ git --version #現在のGitバージョンを表示
git version 2.17.1 (Apple Git-112) #バージョン情報

$ brew list #Homebrewからインストールしたパッケージを表示
#ツールをインストールしていなければ何も表示されない

なお本記事を執筆時点のHomebrewでインストール可能なGit最新バージョンは v2.19.1 です.
続いてHomebrewからGitをインストールします.
このインストールの結果が事前に調べていたものと異なりました.
参考の為にGitインストールコマンドからインストール完了までのプロセスを記載します.

ターミナル.app
$ brew install git #Homebrewを使ってgitをインストール
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
git               micronaut         mkvtoolnix        mscgen            rustup-init

==> Installing dependencies for git: gettext, pcre2
==> Installing git dependency: gettext
==> Downloading https://homebrew.bintray.com/bottles/gettext-0.19.8.1.mojave.bottle.tar.g
######################################################################## 100.0%
==> Pouring gettext-0.19.8.1.mojave.bottle.tar.gz
==> Caveats
gettext is keg-only, which means it was not symlinked into /usr/local,
because macOS provides the BSD gettext library & some software gets confused if both are in the library path.

If you need to have gettext first in your PATH run:
  echo 'export PATH="/usr/local/opt/gettext/bin:$PATH"' >> ~/.bash_profile

For compilers to find gettext you may need to set:
  export LDFLAGS="-L/usr/local/opt/gettext/lib"
  export CPPFLAGS="-I/usr/local/opt/gettext/include"

==> Summary
🍺  /usr/local/Cellar/gettext/0.19.8.1: 1,935 files, 16.9MB
==> Installing git dependency: pcre2
==> Downloading https://homebrew.bintray.com/bottles/pcre2-10.32.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Pouring pcre2-10.32.mojave.bottle.tar.gz
🍺  /usr/local/Cellar/pcre2/10.32: 224 files, 5.5MB
==> Installing git
==> Downloading https://homebrew.bintray.com/bottles/git-2.19.1.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Pouring git-2.19.1.mojave.bottle.tar.gz
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

zsh completions and functions have been installed to:
  /usr/local/share/zsh/site-functions

Emacs Lisp files have been installed to:
  /usr/local/share/emacs/site-lisp/git
==> Summary
🍺  /usr/local/Cellar/git/2.19.1: 1,518 files, 40.1MB
==> Caveats
==> gettext
gettext is keg-only, which means it was not symlinked into /usr/local,
because macOS provides the BSD gettext library & some software gets confused if both are in the library path.

If you need to have gettext first in your PATH run:
  echo 'export PATH="/usr/local/opt/gettext/bin:$PATH"' >> ~/.bash_profile

For compilers to find gettext you may need to set:
  export LDFLAGS="-L/usr/local/opt/gettext/lib"
  export CPPFLAGS="-I/usr/local/opt/gettext/include"

==> git
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

zsh completions and functions have been installed to:
  /usr/local/share/zsh/site-functions

Emacs Lisp files have been installed to:
  /usr/local/share/emacs/site-lisp/git

プロセスを読むとGitはどうやら正常にインストールされたようですが, Git以外にもgettext, pcre2の2つのパッケージが同時にインストールされています. 事前情報ではインストールされるパッケージはGitのみだと思っていたのですが, これがMojaveにアップデートした影響なのかは結局わかりませんでした(どなたかご存知でしたら教えてください).
そしてこれらはGitと依存関係にあるようなので, 迂闊に削除するわけにもいきません.2


2018/10/12 追記
パッケージによっては他のファイルとの依存関係が存在するものがあります.
パッケージに関する情報は,インストール前にbrew info パッケージ名で確認できます.
本記事執筆時には,このコマンドを把握していませんでした(汗).


とりあえず状況確認を含め次のステップへ.

Gitのパスを通す

現状を確認してみます.

ターミナル.app
$ brew list #Homebrewからインストールしたパッケージを表示
gettext git pcre2 #やはりインストールされたパッケージは3つ...

$ brew deps --tree git #Homebrewからインストールしたパッケージ(git)の依存関係をツリー構造で表示
git
├── gettext
└── pcre2

$ which git #gitコマンドの実行ファイルがどこに格納されているのか表示
/usr/local/bin/git #Homebrew下のパッケージコマンドはエイリアスとしてこのディレクトリに格納される(正常)

$ git --version #バージョンを確認
git version 2.17.1 (Apple Git-112) #しかしバージョンは古いまま(要修正)

$ brew doctor #Homebrewのインストールの問題を確認
Your system is ready to brew. #むむっ!

少し調べると, どうやらgettextは翻訳に関するライブラリなるものらしい.
gettext - Wikipedia
そしてpcre2は正規表現に関するライブラリだそうです.
Perl Compatible Regular Expressions - Wikipedia

ひとまずこれらは置いといて, gitコマンドのパスを通してHomebrew管理下に置こうと思ったのですがbrew doctorの結果は正常...
他の方の記事やブログなどではbrew doctorを叩くと解決方法をHomebrewが表示してくれるようですが, どうやら状況が違うようです.
仕方ないので, Gitのインストールプロセスで表示された,
下記gettextのメッセージを実行します.


2018/10/12 追記
この時点でターミナルを再起動していれば,おそらくgitコマンドのパスはHomebrew下のものになったと思われます.
知識不足です...


ターミナル.app
#gettextのメッセージ(再掲)
==> Caveats
==> gettext
gettext is keg-only, which means it was not symlinked into /usr/local,
because macOS provides the BSD gettext library & some software gets confused if both are in the library path.

If you need to have gettext first in your PATH run:
  echo 'export PATH="/usr/local/opt/gettext/bin:$PATH"' >> ~/.bash_profile #このコマンドを実行する

最後のメッセージをコピペしてEnter.

ターミナル.app
$ echo 'export PATH="/usr/local/opt/gettext/bin:$PATH"' >> ~/.bash_profile #''で囲まれたコマンドが,ホームディレクトリに作成された.bash_profileに追記される

$ source ~/.bash_profile #シェルの設定(.bash_profile)を即座に反映させる

$ git --version #バージョンを再度確認
git version 2.19.1 #解決しちゃった

解決しました...
これで今後Gitのバージョン更新をbrew upgradeコマンドで簡単に行なえます.
ただ知識不足の為,gettextpcre2の役割や使い方までよくわかっていません(どなたかご存知でしたら教えてください).

補足

Gitの運用には影響しないとは思われますが, 参考までに.bash_profile作成後のgettextの情報を記載しておきます.

ターミナル.app
$ which gettext #gettextコマンドの実行ファイルがどこに格納されているのか表示
/usr/local/opt/gettext/bin/gettext

$ gettext --version #gettextのバージョン情報を表示
gettext (GNU gettext-runtime) 0.19.8.1
Copyright (C) 1995-1997, 2000-2007 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

[参考訳]
ライセンス GPLv3+: GNU GPL バージョン 3 またはそれ以降 <http://gnu.org/licenses/gpl.html>
これはフリー・ソフトウェアです. 改変と再配布は自由です.
法で許された範囲内で無保証です.
作者 Ulrich Drepper.

参考記事

以下の記事を参考にさせて頂きました.ありがとうございます.

パッケージマネージャー及びHomebrewについて

Gitのインストールについて

ターミナルコマンドについて


  1. macOS Sierra 以前のOSではXcodeのサポートが終了しているらしく,これまで使ったことがありませんでした. 

  2. プロセス内で, Bash completion, zsh completions and functions, Emacs Lisp filesなどがインストールされましたが, これらはBash, zsh, Emacsそれぞれでgitコマンドを補完する役割を果たすようなので, 本記事では無視します. 

19
21
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
21