一、编译方式安装

1.下载最新版本源码
https://mirrors.edge.kernel.org/pub/software/scm/git/

  1. yum install -y wget
  2. wget -O /tmp/git-2.21.0.tar.gz https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.21.0.tar.gz

2.解压编译

  1. # 安装编译依赖
  2. yum install -y curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker
  3. # 解压
  4. tar -zxf /tmp/git-2.21.0.tar.gz -C /tmp/
  5. cd /tmp/git-2.21.0
  6. # 检验相关依赖,设置安装路径
  7. ./configure --prefix=/usr/local/git
  8. # 编译安装
  9. make && make install


3.配置全局环境变量

  1. # 删除已有的 git
  2. yum remove git
  3. # 配置环境变量
  4. vim /etc/profile
  5. # GIT_HOME
  6. GIT_HOME=/usr/local/git
  7. export PATH=$PATH:$GIT_HOME/bin
  8. # 刷新
  9. source /etc/profile