centos 7.3 如何安装最新版 git

2019-08-31 13:24发布

centos 7.3 默认安装的 git 版本是 1.8.3.1 ,请问如何升级至最新版?

标签: linux centos git
4条回答
该账号已被封号
2楼-- · 2019-08-31 14:03

从 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 ,虽然不是最新版,但够用了。

查看更多
We Are One
3楼-- · 2019-08-31 14:11

先卸载旧版本,再下载最新版本拖进去然后安装新版本。
linux下git升级

查看更多
Animai°情兽
4楼-- · 2019-08-31 14:13

特意整了个 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

码完收工

查看更多
登录 后发表回答