CentOS 7 yum和源码两种方式升级安装最新版本git-2.x

882 阅读1分钟

使用yum安装

检查当前版本

$ git --version
git version 1.8.3.1

移除旧版git

sudo yum -y remove git 
sudo yum -y remove git-*

添加 End Point CentOS 7 repo


sudo yum -y install https://packages.endpointdev.com/rhel/7/os/x86_64/endpoint-repo.x86_64.rpm

安装

sudo yum install -y git
sudo yum install -y git
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
endpoint                                                                                                                       | 2.9 kB  00:00:00
endpoint/7/x86_64/primary_db                                                                                                   | 645 kB  00:00:17
Resolving Dependencies
--> Running transaction check
---> Package git.x86_64 0:1.8.3.1-23.el7_8 will be updated
--> Processing Dependency: git = 1.8.3.1-23.el7_8 for package: perl-Git-1.8.3.1-23.el7_8.noarch
---> Package git.x86_64 0:2.37.1-1.ep7 will be an update
--> Processing Dependency: git-core = 2.37.1-1.ep7 for package: git-2.37.1-1.ep7.x86_64
--> Processing Dependency: git-core-doc = 2.37.1-1.ep7 for package: git-2.37.1-1.ep7.x86_64
--> Running transaction check
---> Package git-core.x86_64 0:2.37.1-1.ep7 will be installed
--> Processing Dependency: libpcre2-8.so.0()(64bit) for package: git-core-2.37.1-1.ep7.x86_64
---> Package git-core-doc.noarch 0:2.37.1-1.ep7 will be installed
---> Package perl-Git.noarch 0:1.8.3.1-23.el7_8 will be updated
---> Package perl-Git.noarch 0:2.37.1-1.ep7 will be an update
--> Running transaction check
---> Package pcre2.x86_64 0:10.23-2.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

======================================================================================================================================================
 Package                               Arch                            Version                                Repository                         Size
======================================================================================================================================================
Updating:
 git                                   x86_64                          2.37.1-1.ep7                           endpoint                           70 k
Installing for dependencies:
 git-core                              x86_64                          2.37.1-1.ep7                           endpoint                          8.1 M
 git-core-doc                          noarch                          2.37.1-1.ep7                           endpoint                          2.8 M
 pcre2                                 x86_64                          10.23-2.el7                            base                              201 k
Updating for dependencies:
 perl-Git                              noarch                          2.37.1-1.ep7                           endpoint                           46 k

Transaction Summary
======================================================================================================================================================
Install             ( 3 Dependent packages)
Upgrade  1 Package  (+1 Dependent package)

Total download size: 11 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/5): git-2.37.1-1.ep7.x86_64.rpm                                                                                             |  70 kB  00:00:16
(2/5): pcre2-10.23-2.el7.x86_64.rpm                                                                                            | 201 kB  00:00:00
(3/5): git-core-doc-2.37.1-1.ep7.noarch.rpm                                                                                    | 2.8 MB  00:00:02
(4/5): perl-Git-2.37.1-1.ep7.noarch.rpm                                                                                        |  46 kB  00:00:00
(5/5): git-core-2.37.1-1.ep7.x86_64.rpm                                                                                        | 8.1 MB  00:00:23
------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                 479 kB/s |  11 MB  00:00:23
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : pcre2-10.23-2.el7.x86_64                                                                                                           1/7
  Installing : git-core-2.37.1-1.ep7.x86_64                                                                                                       2/7
  Installing : git-core-doc-2.37.1-1.ep7.noarch                                                                                                   3/7
  Updating   : perl-Git-2.37.1-1.ep7.noarch                                                                                                       4/7
  Updating   : git-2.37.1-1.ep7.x86_64                                                                                                            5/7
  Cleanup    : perl-Git-1.8.3.1-23.el7_8.noarch                                                                                                   6/7
  Cleanup    : git-1.8.3.1-23.el7_8.x86_64                                                                                                        7/7
  Verifying  : pcre2-10.23-2.el7.x86_64                                                                                                           1/7
  Verifying  : git-2.37.1-1.ep7.x86_64                                                                                                            2/7
  Verifying  : git-core-2.37.1-1.ep7.x86_64                                                                                                       3/7
  Verifying  : perl-Git-2.37.1-1.ep7.noarch                                                                                                       4/7
  Verifying  : git-core-doc-2.37.1-1.ep7.noarch                                                                                                   5/7
  Verifying  : git-1.8.3.1-23.el7_8.x86_64                                                                                                        6/7
  Verifying  : perl-Git-1.8.3.1-23.el7_8.noarch                                                                                                   7/7

Dependency Installed:
  git-core.x86_64 0:2.37.1-1.ep7                   git-core-doc.noarch 0:2.37.1-1.ep7                   pcre2.x86_64 0:10.23-2.el7

Updated:
  git.x86_64 0:2.37.1-1.ep7

Dependency Updated:
  perl-Git.noarch 0:2.37.1-1.ep7

Complete!

验证

$ git --version
git version 2.37.1

使用源码安装

移除旧版git

sudo yum -y remove git* 

安装依赖包

sudo yum -y install epel-release 
sudo yum -y groupinstall "Development Tools" 
sudo yum -y install wget perl-CPAN gettext-devel perl-devel openssl-devel zlib-devel curl-devel expat-devel getopt asciidoc xmlto docbook2X 
sudo ln -s /usr/bin/db2x_docbook2texi /usr/bin/docbook2x-texi
sudo yum -y install wget curl

下载源码包

export VER="v2.37.1" 
wget https://github.com/git/git/archive/${VER}.tar.gz

编译安装

tar -xvf ${VER}.tar.gz 
rm -f ${VER}.tar.gz 
cd git-* 
make configure 
sudo ./configure --prefix=/usr 
sudo make 
sudo make install

验证

$ git --version
git version 2.37.1