LoginSignup
3

More than 3 years have passed since last update.

CentOSにソースから最新版のgitをインストール

Last updated at Posted at 2019-06-18

本項ではCentOS環境にソースから最新バージョンのgitをインストールする手順についてまとめていきます。

サーバ環境

項目 バージョン
CentOS 7.6.1810

背景

gitをソースからインストールする背景としては、以下のようにCentOS上のデフォルトの yum reposiotryの情報では、gitのバージョンが1.8.3.1と古く最新バージョンの gitのコマンドを利用できないという課題があります。
そこで、本項ではこちらの情報を参考に最新バージョンの gitをインストールする手順を記載します。

yum info gitの結果

$ sudo yum info git
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ty1.mirror.newmediaexpress.com
 * epel: mirror.pregi.net
 * extras: ty1.mirror.newmediaexpress.com
 * updates: ty1.mirror.newmediaexpress.com
Installed Packages
Name        : git
Arch        : x86_64
Version     : 1.8.3.1
Release     : 20.el7
Size        : 22 M
Repo        : installed
From repo   : updates
Summary     : Fast Version Control System
URL         : http://git-scm.com/
License     : GPLv2
Description : Git is a fast, scalable, distributed revision control system with an
            : unusually rich command set that provides both high-level operations
            : and full access to internals.
            :
            : The git rpm installs the core tools with minimal dependencies.  To
            : install all git packages, including tools for integrating with other
            : SCMs, install the git-all meta-package.

依存関係のあるパッケージをインストール

ソースから gitをインストールするために、まずはじめに、依存関係のあるパッケージをインストールしていきます。

コンパイルに必要なパッケージをインストール

$ sudo yum install -y wget gcc

依存関係のあるパッケージをインストール

$ sudo yum install -y curl-devel expat-devel gettext-devel openssl-devel perl-devel zlib-devel

最新版のgitのtarballをダウンロード

こちら のサイトから git のtarballをダウンロードしておきます。

本投稿では、バージョン2.9.4をダウンロードします。

$ cd /usr/local/src/  # ソースファイルの保存先フォルダに移動
$ sudo wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.9.4.tar.gz
--2019-06-18 23:26:41--  https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.9.4.tar.gz
mirrors.edge.kernel.org (mirrors.edge.kernel.org) をDNSに問いあわせています... 147.75.69.165, 2604:1380:1000:8100::1
mirrors.edge.kernel.org (mirrors.edge.kernel.org)|147.75.69.165|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 5921866 (5.6M) [application/x-gzip]
`git-2.9.4.tar.gz' に保存中

100%[=============================================================================>] 5,921,866    105KB/s 時間 34s

2019-06-18 23:27:16 (172 KB/s) - `git-2.9.4.tar.gz' へ保存完了 [5921866/5921866]

$ ls -l
total 5784
-rw-r--r--. 1 root root 5921866  5月 10  2017 git-2.9.4.tar.gz

ソースから gitをインストール

続いて、ダウンロードしてきたtarballを解凍し、ソースからgitをインストールしていきます。

tarballの解凍

$ sudo tar -zxf git-2.9.4.tar.gz
$ cd git-2.9.4/

make step1

$ sudo make configure
GIT_VERSION = 2.9.4
    GEN configure

make step2

$ sudo ./configure --prefix=/usr
configure: Setting lib to 'lib' (the default)
configure: Will try -pthread then -lpthread to enable POSIX Threads.
configure: CHECKS for site configuration
.
.
.
configure: creating ./config.status
config.status: creating config.mak.autogen
config.status: executing config.mak.autogen commands

make step3

$ sudo make all
    * new build flags
    CC credential-store.o
    * new link flags
    CC common-main.o
    CC abspath.o
    CC advice.o
    CC alias.o
    .
    .
    .
    GEN bin-wrappers/test-svn-fe
    GEN bin-wrappers/test-urlmatch-normalization
    GEN bin-wrappers/test-wildmatch
    GEN git-remote-testgit

make installでインストール

make installコマンドでインストールしていきます。

$ sudo make install

gitのバージョン確認

インストールした gitのバージョンを確認し、gitのバージョンが2.9.4になっていればソースインストールの完了です。

$ git version
git version 2.9.4

最新バージョンへのアップデート

最後にgitのインストール後に最新バージョンへアップデートしていきます。

最新バージョンの gitリポジトリをダウンロード

gitのインストール後は gitコマンドが使用可能になるので、git clone git://git.kernel.org/pub/scm/git/git.git で最新バージョンのリポジトリをダウンロードしていきます。

$ sudo git clone git://git.kernel.org/pub/scm/git/git.git
Cloning into 'git'...
remote: Counting objects: 270102, done.
remote: Compressing objects: 100% (64378/64378), done.
remote: Total 270102 (delta 203589), reused 269929 (delta 203497)
Receiving objects: 100% (270102/270102), 60.71 MiB | 330.00 KiB/s, done.
Resolving deltas: 100% (203589/203589), done.
Checking connectivity... done.
$ ls -l
total 40
drwxr-xr-x. 31 root root 24576  6月 18 16:07 git

make installの実行

前回の2.9.4をインストールした手順と同様に以下のコマンドを実行し、最新版のgitのインストールを行います。

$ cd git
$ sudo make configure
$ sudo ./configure --prefix=/usr
$ sudo make all
$ sudo make install

gitが最新バージョンに更新されていることを確認

最後に gitのバージョンを確認し、最新バージョンのgitになっていれば完了です。
※ 2019年6月時点の最新バージョンは 2.22.0のため、以下ではバージョン2.22.0になっています。

$ git version
git version 2.22.0.190.ga6a95cd

参考文献

  1. Git - Gitのインストール, https://git-scm.com/book/ja/v2/%E4%BD%BF%E3%81%84%E5%A7%8B%E3%82%81%E3%82%8B-Git%E3%81%AE%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB, Online; accessed 19-June-2019.
  2. Index of pub_software_scm_git, https://mirrors.edge.kernel.org/pub/software/scm/git/, Online; accessed 19-June-2019.
  3. git_git_ Git Source Code Mirror - This is a publish-only repository and all pull requests are ignored. Please follow Documentation_SubmittingPatches procedure for any of your improvements., https://github.com/git/git, Online; accessed 19-June-2019.

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
3