Linux(CentOS)で普通にyum install gitでインストールされるGitのバージョンって古いですよね、1.0系統だし。
やっぱり使うなら最新バージョンの2.0系統を使いたい。
というわけで、自分がGitの最新版をインストールした方法を書きました。
概要
下記の手順で最新版インストール
- 最近パッケージを揃えている「IUSリポジトリ」をインストール(登録)する
 - 
yum installでIUSリポジトリからgitの最新版をインストールする 
※既に1.0系のGitをインストールしてるときは、最初にyum remove gitでアンインストールしときましょう
IUSリポジトリの登録
下記のコマンドで最新版を揃えているIUSリポジトリを登録(CentOS7の場合)
# yum -y install https://centos7.iuscommunity.org/ius-release.rpm
- 
-y全ての問い合わせに「yes」で応答したものとして実行する - cent OS6の場合はURLを
centos7→centos6にする 
IUSはCentOSから正式に認証されているが、公式ではないのでデフォルトで使用されるリポジトリから外したほうがよいらしい
/etc/yum.repos.d/ius.repoがリポジトリの設定ファイルなので
# vi /etc/yum.repos.d/ius.repo
下記のように編集
[ius]
...(略)...
enabled=0 #enabled=1から変更
...(略)...
IUSリポジトリからGitの最新版をインストール
下記のコマンドで最新版をインストールできます(base,epel,extras,updatesがデフォルトで使用されるリポジトリのとき)
# yum install git --enablerepo=ius --disablerepo=base,epel,extras,updates
- 
--enablerepo=[リポジトリ名]使用するリポジトリを指定(デフォルトで使用するリポジトリでないときコマンドで指定する) - 
--disablerepo=[リポジトリ名]使用しないリポジトリを指定(デフォルトで使用されるリポジトリを除きたいときコマンドで指定する) - 上記オプションがない通常時は、デフォルトで使用されるリポジトリからインストールされる
 
デフォルト使用のリポジトリの確認
下記コマンドで確認
# yum repolist
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * epel: mirror.dmmlabs.jp
 * extras: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
repo id                                repo name                                                                      status
base                                   CentOS-6 - Base                                                                 6,706
epel                                   Extra Packages for Enterprise Linux 6 - x86_64                                 12,457
extras                                 CentOS-6 - Extras                                                                  52
updates                                CentOS-6 - Updates                                                                950
repolist: 20,165
上記だと、base,epel,extras,updatesのリポジトリがデフォルトリポジトリになる。
デフォルト以外も含めた全てのリポジトリのリストは下記コマンドを使用。
# yum repolist all
statusが「enabled」だと「デフォルト使用」、「disabled」が「非デフォルト使用」
下記のエラーが出たときは
Loaded plugins: fastestmirror, security
Setting up Install Process
Loading mirror speeds from cached hostfile
 * ius: hkg.mirror.rackspace.com
Resolving Dependencies
--> Running transaction check
---> Package git2u.x86_64 0:2.16.1-1.ius.centos6 will be installed
--> Processing Dependency: git2u-core = 2.16.1-1.ius.centos6 for package: git2u-2.16.1-1.ius.centos6.x86_64
--> Processing Dependency: git2u-core-doc = 2.16.1-1.ius.centos6 for package: git2u-2.16.1-1.ius.centos6.x86_64
--> Processing Dependency: git2u-perl-Git = 2.16.1-1.ius.centos6 for package: git2u-2.16.1-1.ius.centos6.x86_64
--> Processing Dependency: perl(Git) for package: git2u-2.16.1-1.ius.centos6.x86_64
--> Processing Dependency: perl(Git::I18N) for package: git2u-2.16.1-1.ius.centos6.x86_64
--> Processing Dependency: perl(Term::ReadKey) for package: git2u-2.16.1-1.ius.centos6.x86_64
--> Running transaction check
---> Package git2u.x86_64 0:2.16.1-1.ius.centos6 will be installed
--> Processing Dependency: perl(Term::ReadKey) for package: git2u-2.16.1-1.ius.centos6.x86_64
---> Package git2u-core.x86_64 0:2.16.1-1.ius.centos6 will be installed
---> Package git2u-core-doc.noarch 0:2.16.1-1.ius.centos6 will be installed
---> Package git2u-perl-Git.noarch 0:2.16.1-1.ius.centos6 will be installed
--> Finished Dependency Resolution
Error: Package: git2u-2.16.1-1.ius.centos6.x86_64 (ius)
           Requires: perl(Term::ReadKey)
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest
どうやら「perl(Term::ReadKey)パッケージ」がIUSリポジトリにないようなので通常のリポジトリから下記コマンドで先にインストール
# yum install perl-TermReadKey
最新バージョンか確認
# git --version
git version 2.16.1
やった、最新バージョンをインストールできた!