Gitをソースからビルドしてインストールする方法

スポンサーリンク

Git をソースからビルドしてインストールする方法です。

ダウンロード

ソースファイルは GitHub 上のリポジトリか Kernel.org からダウンロードします。

$ curl -LO https://www.kernel.org/pub/software/scm/git/git-2.12.2.tar.gz
$ tar zxvf git-2.12.2.tar.gz
$ cd git-2.12.2/

GitHub - git/git: Git Source Code Mirror
Git source repository

コンパイルとインストール

Git公式の手順は以下の通りですが、Makefile はリポジトリに含まれてるためmake all && sudo make prefix=/usr/local installのみでも大丈夫です。依存ライブラリを先にインストールしてください。

$ make configure
$ ./configure --prefix=/usr/local
$ make all doc info
$ sudo make install install-doc install-html install-info

依存ライブラリ

依存ライブラリは以下の通りですが、doc をインストールしない場合asciidoc xmlto docbook2xは不要です。

$ sudo apt-get install libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev
$ sudo apt-get install asciidoc xmlto docbook2x

make configureを実行する場合はautoconfも必要です。

$ sudo apt-get install autoconf

Git - Gitのインストール

Gitのアップデート

インストールした Git をアップデートするにはリポジトリをクローンします。

$ git clone git://git.kernel.org/pub/scm/git/git.git

新しいバージョンが出たら最新のソースを取得して再度コンパイルしてください。

$ git pull
$ make all && sudo make prefix=/usr/local install
$ git --version

コンパイルエラーとライブラリ

コンパイル時に発生するエラーと必要なライブラリです。

man allの実行時エラー

In file included from http.c:2:0:
http.h:6:23: fatal error: curl/curl.h: No such file or directory
 #include <curl/curl.h>
                       ^
compilation terminated.
make: *** [http.o] Error 1
$ sudo apt-get install libcurl4-gnutls-dev
http-push.c:18:19: fatal error: expat.h: No such file or directory
 #include <expat.h>
                   ^
compilation terminated.
make: *** [http-push.o] Error 1
$ sudo apt-get install libexpat1-dev
GITGUI_VERSION = 0.20.0.44.gccc98
    * new locations or Tcl/Tk interpreter
    GEN git-gui
    INDEX lib/
    * tclsh failed; using unoptimized loading
    MSGFMT    po/bg.msg make[1]: *** [po/bg.msg] Error 127
make: *** [all] Error 2
$ sudo apt-get install gettext
    * tclsh failed; using unoptimized loading
    MSGFMT    po/ru.msg Makefile:249: recipe for target 'po/ru.msg' failed
make[1]: *** [po/ru.msg] Error 127
Makefile:1653: recipe for target 'all' failed
make: *** [all] Error 2
$ sudo apt-get install gettext

man all docの実行時エラー

/bin/sh: 2: asciidoc: not found
Makefile:305: recipe for target 'git-fetch-pack.html' failed
make[1]: *** [git-fetch-pack.html] Error 127
make[1]: Leaving directory '/home/vagrant/git-2.0.1/Documentation'
Makefile:2082: recipe for target 'doc' failed
make: *** [doc] Error 2
$ sudo apt-get install asciidoc

make all doc infoの実行時エラー

/bin/sh: 2: docbook2x-texi: not found
Makefile:355: recipe for target 'user-manual.texi' failed
make[1]: *** [user-manual.texi] Error 127
make[1]: Leaving directory '/home/vagrant/git-2.0.1/Documentation'
Makefile:2091: recipe for target 'info' failed
make: *** [info] Error 2
$ sudo apt-get install docbook2x