centos 7 升级 git 版本(通过安装 ius 源的方式)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lovefengruoqing/article/details/83819591

查看系统相关信息

查看CentOS的版本号

[root@localhost ~]# cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core) 

查看内核版本

[root@localhost ~]# uname -r
3.10.0-693.el7.x86_64

查看 git 版本

[root@localhost haskell]# git version
git version 1.8.3.1

可以看到,我的 CentOS 7 中自带的是 1.8.3.1 版本的git,我想升级到最新版本,于是我进入了git官网,去找我该怎么升级我的git版本。

进入相关下载页面(https://git-scm.com/download/linux) 可以看到以下信息:
在这里插入图片描述
我们可以看到,我们使用的 Red Hat 有两种升级我们 git 版本的方式,分别是:

  1. 源码编译安装的方式
  2. 用第三方 yum 源,来更新我们的 git 版本

通过安装第三方 yum 源的方式来更新git

下载对应的 yum 源

我们点击进入 the IUS Community Project 网站,首页是这样的:
在这里插入图片描述
可以看到,这个页面很友好,很干净。简单的介绍了一下项目用途,项目哲学,介绍了以下怎么使用。

然后我们可以点击下图中的这个链接,进入对应的页面:
在这里插入图片描述
这里为了方便直接,我直接在这里放出页面地址:https://ius.io/GettingStarted/

点进去以后,找到下面这一段:
在这里插入图片描述
用我四级的水平稍微理解了一下,可以明白,我么们用的 CentOS 系统,可以跳过安装 epel-release ,直接进入第二步了。

然后我们就能回到我们的 Linux,通过 wget 下载对应版本的 rpm 源。

[root@localhost ~]# wget https://centos7.iuscommunity.org/ius-release.rpm
--2018-11-07 09:29:06--  https://centos7.iuscommunity.org/ius-release.rpm
正在解析主机 centos7.iuscommunity.org (centos7.iuscommunity.org)... 162.242.221.48, 2001:4802:7801:102:be76:4eff:fe21:14aa
正在连接 centos7.iuscommunity.org (centos7.iuscommunity.org)|162.242.221.48|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 301 Moved Permanently
位置:https://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/ius-release-1.0-15.ius.centos7.noarch.rpm [跟随至新的 URL]
--2018-11-07 09:29:11--  https://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/ius-release-1.0-15.ius.centos7.noarch.rpm
正在解析主机 dl.iuscommunity.org (dl.iuscommunity.org)... 146.20.25.47, 2001:4802:7901:0:4ccc:ff11:0:a
正在连接 dl.iuscommunity.org (dl.iuscommunity.org)|146.20.25.47|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:8340 (8.1K) [application/x-redhat-package-manager]
正在保存至: “ius-release.rpm”

100%[================================================================>] 8,340       --.-K/s 用时 0s      

2018-11-07 09:29:15 (95.7 MB/s) - 已保存 “ius-release.rpm” [8340/8340])

如果你还没有安装 wget,那么这里安利一下我之前写过的一篇安装 python3 的文章,https://blog.csdn.net/lovefengruoqing/article/details/79284573,里面有安装 wget 的教程,希望能帮到你。

安装 yum 源

[root@localhost ~]# rpm -i ius-release.rpm 
警告:ius-release.rpm: 头V4 DSA/SHA1 Signature, 密钥 ID 9cd4953f: NOKEY

删除掉已经存在的 git

如果不删除,直接安装,会报错:

[root@localhost ~]# yum install git2u
已加载插件:fastestmirror, langpacks, replace
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * ius: hkg.mirror.rackspace.com
 * updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 git2u.x86_64.0.2.16.5-1.ius.centos7 将被 安装
--> 正在处理依赖关系 git2u-core = 2.16.5-1.ius.centos7,它被软件包 git2u-2.16.5-1.ius.centos7.x86_64 需要
--> 正在处理依赖关系 git2u-core-doc = 2.16.5-1.ius.centos7,它被软件包 git2u-2.16.5-1.ius.centos7.x86_64 需要
--> 正在处理依赖关系 git2u-perl-Git = 2.16.5-1.ius.centos7,它被软件包 git2u-2.16.5-1.ius.centos7.x86_64 需要
--> 正在检查事务
---> 软件包 git2u-core.x86_64.0.2.16.5-1.ius.centos7 将被 安装
---> 软件包 git2u-core-doc.noarch.0.2.16.5-1.ius.centos7 将被 安装
---> 软件包 git2u-perl-Git.noarch.0.2.16.5-1.ius.centos7 将被 安装
--> 处理 git2u-core-2.16.5-1.ius.centos7.x86_64 与 git-core < 2.16.5 的冲突
--> 处理 git2u-perl-Git-2.16.5-1.ius.centos7.noarch 与 perl-Git < 2.16.5 的冲突
--> 处理 git2u-2.16.5-1.ius.centos7.x86_64 与 git < 2.16.5 的冲突
--> 解决依赖关系完成
错误:git2u-perl-Git conflicts with perl-Git-1.8.3.1-14.el7_5.noarch
错误:git2u conflicts with git-1.8.3.1-14.el7_5.x86_64
错误:git2u-core conflicts with git-1.8.3.1-14.el7_5.x86_64
 您可以尝试添加 --skip-broken 选项来解决该问题
 您可以尝试执行:rpm -Va --nofiles --nodigest

这里需要注意的是,使用ius源安装的软件,一般都会在软件名称后面加上版本号u,我们查询一下就能知道:

[root@localhost ~]# yum info git*u --disablerepo=base,extras,updates --enablerepo=ius
已加载插件:fastestmirror, langpacks, replace
Loading mirror speeds from cached hostfile
 * epel: mirrors.aliyun.com
 * ius: mirrors.tuna.tsinghua.edu.cn
已安装的软件包
名称    :git2u
架构    :x86_64
版本    :2.16.5
发布    :1.ius.centos7
大小    :2.3 M
源    :installed
来自源:ius
简介    : Fast Version Control System
网址    :https://git-scm.com
协议    : GPLv2
描述    : 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 common set of tools which are usually using with
         : small amount of dependencies. To install all git packages, including
         : tools for integrating with other SCMs, install the git-all meta-package.

通过查询得知,在 ius 源中有 2.16.5 版本的 git,这已经比我们系统自带的 1.8.3.1 版本的 git 好多了。

删除掉原本的版本的 git:

yum remove git

安装 ius 源中的 git

安装命令为:

yum install git2u 

安装完成以后检查一下版本:

[root@localhost ~]# git version
git version 2.16.5

恭喜你,你已经成功通过 ius 源,安装了新版本的 git 了。

后记

至于通过源码编译的方式安装 git,我之前写过一篇类似的文章,地址为:https://lovefengruoqing.github.io/blog/CentOS下git最新版本的安装方法.html ,顺便安利一下我用 hexo 搭建的个人博客吧。

猜你喜欢

转载自blog.csdn.net/lovefengruoqing/article/details/83819591
今日推荐