CentOS 6自带的git版本是1.7,

安装编译环境

安装gcc

# yum install gcc gcc-c++ autoconf make automake wget -y

安装依赖包

# yum install perl curl-devel expat-devel gettext-devel openssl-devel zlib-devel -y# yum install cpio texinfo sgml2xml openjade perl-ExtUtils-MakeMaker -y# yum install asciidoc xmlto docbook2X -y    // 为了能够添加更多格式的文档(如 doc, html, info) # ll /usr/bin/db2x_docbook2texi     // 剩下步骤为避免执行make all doc info时报:/bin/sh: line 1: docbook2x-texi: command not found-rwxr-xr-x 1 root root 3762 11月 12 2010 db2x_docbook2texi# ln -s /usr/bin/db2x_docbook2texi /usr/bin/docbook2x-texi# ll /usr/bin/{db2x_docbook2texi,docbook2x-texi}-rwxr-xr-x 1 root root 3762 11月 12 2010 db2x_docbook2texilrwxrwxrwx 1 root root   17 1月  15 12:31 docbook2x-texi -> db2x_docbook2texi

卸载自带的git

# yum remove git -t

源码编译git

下载最新版

# cd /data/toots/# wget https://www.kernel.org/pub/software/scm/git/git-2.15.1.tar.xz

解压

# tar zxvf git-2.15.1.tar.xz# cd git-2.15.1

编译安装

# make configure# ./configure --prefix=/usr/local/git            // 配置安装路径# make all doc info                    // 编译# make install install-doc install-html install-info   // 安装

完成后,你可以使用 Git 来获取 Git 的升级: 可选  

# git clone git://git.kernel.org/pub/scm/git/git.git

修改环境变量

# echo -e "# git\nexport PATH=/usr/local/git/bin:\$PATH"> /etc/profile.d/git.sh# cat /etc/profile.d/git.sh\# git        // 文件内容export PATH=/usr/local/git/bin:$PATH# source /etc/profile

查看是否安装成功

# git --versiongit version 2.15.1