在Linux上使用yum安装Git的最新版本

在Linux(CentOS)上,通过yum install git来安装的Git版本很旧,是1.0系列的。
如果要使用的话,肯定想要使用最新版本的2.0系列。
因此,我写了如何自己安装最新版Git的方法。

简述

请按照以下步骤安装最新版本。

    安装(注册)最近正在归档的“IUS仓库”,可以使用yum install从IUS仓库安装最新版本的git。

如果您已经安装了1.0版本的Git,请首先使用yum remove git进行卸载。

注册IUS存储库

使用下列命令在CentOS7上注册并同步最新版本的IUS软件库:

# 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

当状态为“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

太好了,我成功安装了最新的版本!

参考网站

    • W3G – CentOS7にApache2.4最新版をyum installする

 

    • 【@IT > Linux & OSS > 【 yum 】コマンド(基礎編)

 

    Git公式 – Download for Linux and Unix