源码安装git

系统: Centos

由于系统自带的yum源仓库的git版本较低,所以在官网下载源码进行编译安装

官网地址:https://git-scm.com/
源码下载地址:https://github.com/git/git

  1. 安装旧版本的git拉去git源码(如果是上传到服务器就不用了下载git了)

    [root@localhost ~]# yum -y install git
    
  2. 拉取git源码

    [root@localhost ~]# git clone https://github.com/git/git.git
    
  3. 安装可能需要的依赖

    [root@localhost ~]# yum -y install curl-devel expat-devel openssl-devel zlib-devel gcc-c++
    [root@localhost ~]# yum -y install perl-ExtUtils-MakeMaker automake autoconf libtool make
    
  4. 编译安装

    [root@localhost ~]# cd git/
    [root@localhost ~]# make configure
    [root@localhost git]# ./configure --prefix=/usr/local/git		# 安装在/usr/local目录下
    [root@localhost git]# make && make install
    
  5. 卸载旧的git并将新安装的git设置环境变量

    [root@localhost ~]# yum -y remove git
    [root@localhost ~]# echo 'export GIT_HOME=/usr/local/git' >> /etc/profile
    [root@localhost ~]# echo 'export PATH=$PATH:$GIT_HOME/bin' >> /etc/profile
    
  6. 加载配置文件,并查看git版本

    [root@localhost ~]# source /etc/profile
    [root@localhost ~]# git version
    
    git version 2.43.0
    

猜你喜欢

转载自blog.csdn.net/qq_50247813/article/details/134796157