特意整了个 CentOS 7.3...
[root@icentos ~]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
# 默认源中的 git 版本是 1.8.3.1
[root@icentos~]# yum info git
...
Available Packages
Name : git
Arch : x86_64
Version : 1.8.3.1
Release : 20.el7
Size : 4.4 M
Repo : updates/7/x86_64
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-scm 官网 有这么一句话:
Red Hat Enterprise Linux, Oracle Linux, CentOS, Scientific Linux, et al.
RHEL and derivatives typically ship older versions of git. You can download a tarball and build from source, or use a 3rd-party repository such as the IUS Community Project to obtain a more recent version of git.
那么在 CentOS 7.3 里要安装最新版的 git, 通常可以这么做
# 使用旧版 git 下载最新版 git 源码到本地, 自行编译安装
git clone https://github.com/git/git
# 当然也可以下载官方提供的归档包, 自行编译安装
https://mirrors.edge.kernel.org/pub/software/scm/git/
# 亦或者可以使用三方仓库, 比如 IUS Community Project, 通常比较新, 但可能不是最最新
# 添加 IUS 源
yum install -y https://centos7.iuscommunity.org/ius-release.rpm
# IUS 源的软件名称一般会加上版本号和 u 字母
# 查看 git2u 版本
yum info git2u # 会发现比较新, 但不是最最新, 不过会比 yum 默认源要新很多
# 安装 git2u
yum install -y git2u
# 安装完成后, 再查看下版本咯
[root@icentos ~]# git version
git version 2.16.5
当然, 最后的最后, 如果你已经安装过旧版的 git, 需要先卸载才行
yum remove git
码完收工
这个比较好看.
CentOS 7 安装最新的 Git
https://ehlxr.me/2016/07/30/CentOS-7-%E5%AE%89%E8%A3%85%E6%9C%80%E6%96%B0%E7%9A%84-Git/
从 github 找到了一个最简单安装方法(Install latest git rpm package (IUS version) on CentOS 7):
sudo yum install epel-release
sudo yum install https://centos7.iuscommunity.org/ius-release.rpm
sudo yum update
sudo yum remove git
sudo yum install git2u
安装后的版本是 2.16.5 ,虽然不是最新版,但够用了。