编译安装git

    此文介绍在centos7上采用源码方式编译安装 git 2.9.5

  1. 安装git依赖的库
    1
    [root@centos7 /service/application]#yum -y install gcc gcc-c++ perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker curl-devel expat-devel gettext-devel openssl-devel zlib-devel
  2. 从官网下载git源码包
    1
    [root@centos7 ~/tools]# wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.9.5.tar.xz
  • 解压源码包:
    1
    [root@centos7 ~/tools]#tar -xvf git-2.9.5.tar.xz
  • 进入解压后的目录执行编译配置,编译,编译安装。此处选择的是安装在/service/application目录下。
    1
    2
    3
    4
    [root@centos7 ~/tools]#cd git-2.9.5/
    [root@centos7 ~/tools]#./config --prefix=/service/application
    [root@centos7 ~/tools]#make
    [root@centos7 ~/tools]#make install
  • 加入环境变量
    1
    2
    [root@centos7 ~]# echo "export PATH=/service/application/bin" >> /etc/profile
    [root@centos7 ~]# source /etc/profile

相关错误总结:

  1. 如果在make过程中报如下错误:
    1
    2
    3
       Can't locate ExtUtils/MakeMaker.pm in @INC (@INC contains: inc /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at inc/Module/Install/Makefile.pm line 4.
    BEGIN failed--compilation aborted at inc/Module/Install/Makefile.pm line 4.
    Compilation failed in require at inc/Module/Install.pm line 307.
    说明没有安装 perl-ExtUtils-CBuilder   perl-ExtUtils-MakeMaker 这两个组件,采取yum安装一下即可。