首页 新闻 会员 周边

centos 7.3 如何安装最新版 git

0
悬赏园豆:50 [已解决问题] 解决于 2019-08-31 14:32

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

dudu的主页 dudu | 高人七级 | 园豆:30994
提问于:2019-08-30 21:13
< >
分享
最佳答案
1

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

码完收工

收获园豆:30
taadis | 菜鸟二级 |园豆:211 | 2019-08-31 10:59
其他回答(3)
1

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

收获园豆:10
ycyzharry | 园豆:25653 (高人七级) | 2019-08-30 21:47
0
收获园豆:10
墨镜带佬星 | 园豆:2294 (老鸟四级) | 2019-08-31 00:26
1

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

dudu | 园豆:30994 (高人七级) | 2019-08-31 07:47
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册