因为yum源的最新版本是1.7.x,所以无法通过yum进行更新,下面描述如何通过编译源码进行安装
1.安装需要的依赖
第一步我们需要做的就是确认系统已经安装了编译git时需要的依赖。使用下面的安装命令即可(已经安装过的不会重新再安装)
yum install curl yum install curl-devel yum install zlib-devel yum install openssl-devel yum install perl yum install cpio yum install expat-devel yum install gettext-devel yum install gcc yum install perl-ExtUtils-MakeMaker
当然,为了快速安装,你可以把上面命令写在一行中,一次执行
yum install crul curl-devel zlib-devel openssl-devel perl cpio expat-devel gettext-devel gcc perl-ExtUtils-MakeMaker
2.下载Git
cd /usr/src wget https://www.kernel.org/pub/software/scm/git/git-1.9.4.tar.gz tar xzf git-1.9.4.tar.gz
3.编译
cd git-1.9.4 autoconf ./configure make make install
运行autoconf命令时,如果终端提示no command的话就执行yum install autoconf命令后再试
4.重新指定git命令对应的版本
echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc source /etc/bashrc
不执行这一步将出现git版本仍然是升级前的
5.检查安装/升级后的版本是否正确
git --version
执行以上命令后应该显示
git version 1.9.4
6.安装过程中可能遇到的问题
usr/bin/perl Makefile.PL PREFIX='/usr/local/git' INSTALL_BASE='' --localedir='/usr/local/git/share/locale' Can't locate ExtUtils/MakeMaker.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) <span class="goog_qs-tidbit goog_qs-tidbit-0">at Makefile.PL line 3. BEGIN failed--compilation aborted at Makefile.PL line 3.
出现这个错误的原因是perl-ExtUtils-MakeMaker依赖没有安装成功,执行以下命令重新进行安装
yum install perl-ExtUtils-MakeMaker