一、卸載舊版git
yum?remove?git
二、下載壓縮包并解壓
wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.9.0.tar.gz
tar -zxvf git-2.9.0.tar.gz
三、安裝git安裝時需要用到的一些依賴包
如果解壓后就直接安裝git,可能會碰到很多問題(一開始我就是這樣的),大多數都是安裝時缺少某些必要包導致的.git依賴zlib-devel,openssl-devel,perl,cpio,expat-devel,gettext-devel這些包,所以安裝git之前先確認這些包都有了.以下是缺少這些包會出現的錯誤及解決
1.錯誤一:
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?.)?at?Makefile.PL?line?3. BEGIN?failed–compilation?aborted?at?Makefile.PL?line?3. make[1]:?***?[perl.mak]?Error?2 make:?***?[perl/perl.mak]?Error?2
解決:
yum?install?perl-ExtUtils-MakeMaker?package yum?-y?install?perl-devel?perl-CPAN
2.錯誤二:
/bin/sh:?msgfmt:?command?not?found
解決:
yum?install?gettext-devel
3.錯誤三:
tclsh?failed;?using?unoptimized?loading MSGFMT?po/bg.msg?make[1]:?***?[po/bg.msg]?錯誤?127
解決:
yum?install?tcl?build-essential?tk?gettext
四、安裝git
檢查三步驟里的一些必要包沒問題后,就可進行git安裝了(正常情況下解決三步驟的常見問題后,下面命令執行是不會報錯了,如果還出先錯誤,請根據錯誤百度解決)
cd?git-2.9.0 ./configure?--prefix=/usr/local/git make make?install
五、查看git版本出現bash:git:command not found
git –version時出現bash:git:command not found,而進入安裝目錄/usr/local/git/bin,執行./git –version是git version 2.9.0,可見我們git是已安裝成功了,要想在非安裝目錄下使用git命令,解決辦法如下:
打開/etc/profile, 找到path manipulation那一行,在下面的if then中添加pathmunge命令路徑 (如:pathmunge /usr/loccl/git/bin)。然后執行source /etc/profile, 再次執行git –version就可執行成功,會顯示git的版本號。
六、使用https操作git出現 :fatal: Unable to find remote helper for ‘https’
解決:
yum?install?-y?curl?curl-devel
七、git clone報錯SSL connect error
解決:
yum?update?-y?nss?curl?libcurl
推薦教程:《centos教程》