LoginSignup
24
17

More than 3 years have passed since last update.

CentOS7でYumを使って最新版gitを導入する

Last updated at Posted at 2020-07-18

CentOSでは普通にYumでインストールされるgitのバージョンは1.8.3あたりと、かなり古いものになっています。
やっぱり最新版使いたいよな~ でもソースからビルドするのは嫌だしな~ といった感じで、どうにかしてYumでgitの最新版をインストールするというのが目的です。

概要

環境

CentOS 7.8

手順

正直コレも結果論ですが、以下の手順で最新版がインストールできます。

  1. 1.x系のgitをアンインストールする
  2. gitの最新版パッケージが登録されている「IUSリポジトリ」をインストール(登録)する
  3. IUSリポジトリにない依存関係のパッケージを手動でインストールする
  4. IUSリポジトリからgitの最新版をインストールする

結果論

時間のない方向けで、説明を全て省略した形です。
こんな感じでコマンドを叩くとインストールできました。

$ sudo yum -y remove git
$ sudo yum -y install https://repo.ius.io/ius-release-el7.rpm https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
$ sudo yum install libsecret pcre2
$ sudo yum -y install git --enablerepo=ius --disablerepo=base,epel,extras,updates

結果に至るまでの紆余曲折の流れ

ここからが本題になります。
トラブルシューティング的な意味での参考になるかもなので、お時間があればご覧ください。

普通にやるとどうなるのか

(予めyum updateは走らせてあるという前提で)、まずはgitのバージョンを調べてみます。

$ git --version
git version 1.8.3.1

gitのバージョン2.0が公開されたのは2014年5月らしいので、1.8.3.1とか一体いつのバージョンだよ…

僅かな希望を抱いてアップデートがないか調べてみます。

$ yum info git
Name        : git
Arch        : x86_64
Version     : 1.8.3.1
Release     : 23.el7_8
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.

僅かな希望は一瞬にして打ち砕かれた。

IUSリポジトリの導入

gitの公式ドキュメントによると、IUSというリポジトリを使えばいいとのこと。
IUSの公式ドキュメントを閲覧したところ、次のようにしてIUSのリポジトリを読み込むらしい。

yum install \
https://repo.ius.io/ius-release-el7.rpm \
https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

ということで、言われた通りにインストールする。

$ sudo yum -y install https://repo.ius.io/ius-release-el7.rpm https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

IUSに関しては、デフォルトで使用するリポジトリから外すなどした方が良いらしいんですが、私の環境では最初からenabled=1になっていたので割愛します。

IUSリポジトリからgitをインストール(しようと)する

IUSのリポジトリを使用すると明示した上で、gitをインストールします。
また、旧バージョンのgitが選択されるのを防ぐため、IUS以外の(デフォルトの)リポジトリは使用しないと明示します。

ここで使用する引数がこちら

  • --enablerepo=[リポジトリ名] 使用するリポジトリを指定(デフォルトで使用するリポジトリでないときコマンドで指定する)
  • --disablerepo=[リポジトリ名] 使用しないリポジトリを指定(デフォルトで使用されるリポジトリを除きたいときコマンドで指定する)
$ sudo yum -y install git --enablerepo=ius --disablerepo=base,epel,extras,updates
Resolving Dependencies
--> Running transaction check
---> Package git224.x86_64 0:2.24.2-1.el7.ius will be installed
--> Processing Dependency: perl-Git = 2.24.2-1.el7.ius for package: git224-2.24.2-1.el7.ius.x86_64
--> Processing Dependency: git-core-doc = 2.24.2-1.el7.ius for package: git224-2.24.2-1.el7.ius.x86_64
--> Processing Dependency: git-core = 2.24.2-1.el7.ius for package: git224-2.24.2-1.el7.ius.x86_64
--> Processing Dependency: perl(Git::I18N) for package: git224-2.24.2-1.el7.ius.x86_64
--> Processing Dependency: perl(Git) for package: git224-2.24.2-1.el7.ius.x86_64
--> Processing Dependency: libsecret-1.so.0()(64bit) for package: git224-2.24.2-1.el7.ius.x86_64
--> Running transaction check
---> Package git224.x86_64 0:2.24.2-1.el7.ius will be installed
--> Processing Dependency: libsecret-1.so.0()(64bit) for package: git224-2.24.2-1.el7.ius.x86_64
---> Package git224-core.x86_64 0:2.24.2-1.el7.ius will be installed
--> Processing Dependency: libpcre2-8.so.0()(64bit) for package: git224-core-2.24.2-1.el7.ius.x86_64
---> Package git224-core-doc.noarch 0:2.24.2-1.el7.ius will be installed
---> Package git224-perl-Git.noarch 0:2.24.2-1.el7.ius will be installed
--> Finished Dependency Resolution
Error: Package: git224-2.24.2-1.el7.ius.x86_64 (ius)
           Requires: libsecret-1.so.0()(64bit)
Error: Package: git224-core-2.24.2-1.el7.ius.x86_64 (ius)
           Requires: libpcre2-8.so.0()(64bit)
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

…コケた

依存関係の解決

気を取り直してエラーを読むと、どうやらlibsecret-1.so.0()libpcre2-8.so.0()の依存関係が解決できないらしい。
IUSのリポジトリにないだけで、デフォルトのリポジトリにはあると信じてこれらをインストールしてみます。

エラー文が長くなるだけなので詳細は省きますが、リポジトリに関する引数無しでgit224のインストールを叩くと、git本体はIUSのリポジトリから、その他依存関係のパッケージはデフォルトのリポジトリからという形で、必要なパッケージ一覧を表示できます。
宗教上の問題でgitというパッケージ名でインストールしたいので、ここではインストールを取りやめます。

どうやら、必要なパッケージはlibsecretpcre2のようです。
libpcre2-8.so.0()のパッケージ名はlibpcre2じゃなくてpcre2だったのか… (数十分溶かしました)

$ sudo yum install libsecret pcre2

これで依存関係は解決できた(はずな)ので、再度IUSのリポジトリからgitをインストールしようと試みます。

$ sudo yum -y install git --enablerepo=ius --disablerepo=base,epel,extras,updates
Resolving Dependencies
--> Running transaction check
---> Package git224.x86_64 0:2.24.2-1.el7.ius will be installed
--> Processing Dependency: perl-Git = 2.24.2-1.el7.ius for package: git224-2.24.2-1.el7.ius.x86_64
--> Processing Dependency: git-core-doc = 2.24.2-1.el7.ius for package: git224-2.24.2-1.el7.ius.x86_64
--> Processing Dependency: git-core = 2.24.2-1.el7.ius for package: git224-2.24.2-1.el7.ius.x86_64
--> Processing Dependency: perl(Git::I18N) for package: git224-2.24.2-1.el7.ius.x86_64
--> Processing Dependency: perl(Git) for package: git224-2.24.2-1.el7.ius.x86_64
--> Running transaction check
---> Package git224-core.x86_64 0:2.24.2-1.el7.ius will be installed
---> Package git224-core-doc.noarch 0:2.24.2-1.el7.ius will be installed
---> Package git224-perl-Git.noarch 0:2.24.2-1.el7.ius will be installed
--> Finished Dependency Resolution

Dependencies Resolved

無事インストールできました。
最後に念の為gitのバージョンを確認します。

$ git --version
git version 2.24.2

ということで無事gitの最新版をインストールできました。

参考文献

Git
IUS - Setup
yumでGitの最新版をLinuxにインストールする
さくらVPS Cent OS7.7 でGitを最新バージョンに上げた

24
17
1

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
24
17