首先更新系统(看系统环境,不必须)
yum -y update
yum remove git
安装依赖的包(防止安装过程中因依赖包问题发生异常)
yum -y install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker
----------------------------------------------------------------------------------------------------------------------------------
1、查看当前git版本:git --version
或者https://github.com/git/git/releases
2、官网下载:
wget https://Github.com/Git/Git/archive/v2.16.4.tar.gz
(建议本机迅雷下载rz到服务器,安装yum install lrzsz后rz即可)
解压:tar -zxvf git-2.16.4.tar.gz
3、cd git-2.16.4
4、为了防止git安装完后出现
git clone时候提示fatal: Unable to find remote helper for 'https'
提前先安装libcurl-devel
yum install libcurl-devel
5、移除旧版本git:yum remove git
6、make configure(编译,生成Makfile文件)
如果报错/bin/sh: autoconf: command not found:
安装libtool即可:yum install autoconf automake libtool
正常会打印:GEN configure
执行
7、./configure --prefix=/usr/local/server/git --with-iconv =/usr/local/lib(建议优先尝试后者)
或者
./configure --prefix=/usr/local/server/git --with-iconv --with-curl --with-expat=/usr/local/lib(如果没有安装libiconv请自行安装)
make && make install
①如果报错:cache.h:40:18: fatal error: zlib.h: No such file or directory
安装zlib:yum install zlib、yum install zlib-devel
②如果报错:make[1]: *** [perl.mak] Error 2
安装:yum install perl-ExtUtils-MakeMaker package
8、echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc
或:vim /etc/bashrc
在文件最后加入export PATH=$PATH:/usr/local/server/git/bin 暴露的环境配置
9、source /etc/bashrc
10、git --version
参考文档:https://www.cnblogs.com/BinBinStory/p/7113956.html
编译git时报错: zlib.h: No such file or directory
缺少 zlib的头文件, 开发包没装,
yum install zlib (系统默认已经装上)
yum install zlib-devel