LoginSignup
12
13

More than 3 years have passed since last update.

CentOS7で最新バージョンのgitをインストール

Last updated at Posted at 2019-07-08

目的

GitLab CI環境を構築するところで、gitのバージョンが古すぎてdeployが失敗するケースが発生した。
CentOS7で設置されるgitのバージョンは1.8.xなので、2.xに上げないと行けない。
source compileしてインストールすることよりできればyumでインストールしたい。

git 2.x系をインストール

色々とググって見たけど、qiitaとか他の日本語のWEBで見つけたやり方では様々な依存性の問題が発生した。

ここのやり方では一発で行けたので、紹介する。

$ sudo yum remove git*
$ sudo yum -y install https://repo.ius.io/ius-release-el7.rpm
$ sudo yum-config-manager --disable ius
$ sudo yum -y install git2u-all --enablerepo=ius

Ansibleで既存のplaybookを修正した。

- name: install development yum packages
  yum: name={{ item }} state=present
  with_items:
    - gcc
    - gcc-c++
#    - git
    - openssl-devel
    - readline-devel
    - unzip
    - yum-utils

# - name: install yum packages in order to install the newest git
#   yum: name={{ item }} state=present
#   with_items:
#     - emacs-filesystem
#     - libsecret
#     - pcre

- name: install yum repository in order to install the newest git
  yum:
    name: 'https://repo.ius.io/ius-release-el7.rpm'
    state: present
  register: ius_repository

- name: disable ius repository
  shell: yum-config-manager --disable ius
  when: ius_repository.changed

- name: install the newest git
  yum:
    name: git2u-all
    enablerepo: ius
    # disablerepo: base,epel,extras,updates
    state: present

依存性の問題を解決する為にエラーで指摘されたpackageをインストールして見たけど、切りがない。
次々と他の問題が出てくる。
それでコメントアウトしておいた。

最新バージョンのgitを設置する時、他のrepositoryをdisableにしたら、また失敗した。
他のrepositoryから必要なpackageもあるみたいなので、その部分もコメントアウトした。

$ git --version
git version 2.16.5
$ sudo cat /etc/yum.repos.d/ius.repo
[ius]
name = IUS for Enterprise Linux 7 - $basearch
baseurl = https://repo.ius.io/7/$basearch/
enabled = 0
repo_gpgcheck = 0
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-IUS-7

[ius-debuginfo]
name = IUS for Enterprise Linux 7 - $basearch - Debug
baseurl = https://repo.ius.io/7/$basearch/debug/
enabled = 0
repo_gpgcheck = 0
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-IUS-7

[ius-source]
name = IUS for Enterprise Linux 7 - Source
baseurl = https://repo.ius.io/7/src/
enabled = 0
repo_gpgcheck = 0
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-IUS-7

これでOK。意外と最新バージョンのgitのインストールって難しいね。

12
13
2

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
12
13