由于CentOS用yum安装的版本只有1.x,故需要手动编译安装。

首先,下载git安装包。

从github上下载一个最新版(撰写文章时的最新版为:2.5.0)。

cd /usr/local/src
wget https://github.com/git/git/archive/master.zip
unzip master.zip

由于系统中已存在git,所以先备份现有git。

mv /usr/bin/git{,.bak}  

编译安装

cd /usr/local/src/git-master  
make configure
./configure --prefix=/usr/local/ --with-curl --with-expat
make
make install

拷贝到原有Git所在位置

cp /usr/local/src/git-master/git /usr/bin  

在编译过程中可能会遇到错误,主要原因是minimal版的centos没有相应的工具,可以手动安装一下。

yum -y install gcc automake autoconf libtool make
tclsh failed; using unoptimized loading
yum install -y gettext
[root@lsd ~]# cat /etc/issue CentOS release 6.2 (Final) Kernel r on an m [root@lsd git-1.8.1.2]# make CC credential-store.o In file included from credential-store.c:1: cache.h:19:18: warning: zlib.h: No such file or directory In file included from credential-store.c:1: cache.h:21: error: expected specifier-qualifier-list before ‘z_stream’ make: *** [credential-store.o] Error 1
yum install -y gettext
yum -y install zlib zlib-devel
yum install expat-devel
yum install perl-ExtUtils-MakeMaker package