CentOS7の環境でGitをソースからビルド

git公式サイトのビルド方法がYUMからDNFに変更されていたので、やってみたときの覚書。

環境: CentOS 7.8.2003

ちなみにIUSリポジトリを使うとYUM経由でgit2系を簡単インストールできる(この記事の最後に記載)。

1.ソースをダウンロードしてビルド

公式サイトに従ってビルドツールをインストール。
# dnf install dh-autoreconf curl-devel expat-devel gettext-devel openssl-devel perl-devel zlib-devel

依存関係でgit1系がインストールされた。
(追記:dh-autoreconfはなくてもビルドできたので、dh-autoreconfをインストールしなければ古いgitはインストールされない)

gitのソースをダウンロードして解凍。
# mkdir /opt/software
# cd /opt/software
# curl -O https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.26.2.tar.gz
# tar -xzvf git-2.26.2.tar.gz

ビルド実行
# cd git-2.26.2
# make configure
# ./configure --prefix=/usr
# make all
# make install

確認
# git --version
git version 2.26.2

gitの環境設定
# git config --global user.name "Hoge"
# git config --global user.email "hoge@company.co.jp"


2.gitリポジトリをcloneしてアップデート環境を作っておく

git cloneでダウンロードされるサイズは600MBくらい。
必要になったときでいいと思う。
# cd /opt/software/
# git clone git://git.kernel.org/pub/scm/git/git.git
# cd git
# git tag
# git checkout v2.26.2

ビルドコマンドは同じ。
# make configure
# ./configure --prefix=/usr
# make all
# make install

カレントディレクトリの容量確認。
# du -hx --max-depth=1 ./


3.IUSリポジトリを使ってDNF(YUM)管理

IUS公式サイトの通りにリポジトリ追加。
# yum install https://repo.ius.io/ius-release-el7.rpm 

gitを検索
# dnf search git2

インストール
# dnf install git222
エラー:
 問題: problem with installed package git-1.8.3.1-22.el7_8.x86_64
  - package git222-2.22.2-1.el7.ius.x86_64 conflicts with git < 2.22.2-1.el7.ius provided by git-1.8.3.1-22.el7_8.x86_64
  - package git222-2.22.2-1.el7.ius.x86_64 conflicts with git < 2.22.2-1.el7.ius provided by git-1.8.3.1-21.el7_7.x86_64
  - conflicting requests
  - package git222-2.22.3-1.el7.ius.x86_64 conflicts with git < 2.22.3-1.el7.ius provided by git-1.8.3.1-22.el7_8.x86_64
  - package git222-2.22.3-1.el7.ius.x86_64 conflicts with git < 2.22.3-1.el7.ius provided by git-1.8.3.1-21.el7_7.x86_64

一旦gitを削除してからインストールし直し。
# dnf remove git
# dnf install git222

確認
# git --version
git version 2.22.3

ちなみにこの後gitビルドしたらmake allが通った。
dh-autoreconfはいらないみたい。


【関連記事】