Git是一款免費(fèi)牍帚、開(kāi)源的分布式版本控制系統(tǒng)儡遮,用于敏捷高效地處理任何或小或大的項(xiàng)目。
很多yum源上自動(dòng)安裝的git版本為1.7.1暗赶,而Github及其他使用Coding管理項(xiàng)目時(shí)需要的Git版本最低都不能低于1.7.2 鄙币。所以我們一般不用yum -y install git
這種方法,而是下載git源碼編譯安裝比較新的版本蹂随。如下是在CentOS7上編譯安裝步驟:
- 刪除已有的git
[root@localhost ~]# git --version //查看當(dāng)前版本號(hào)
git version 1.8.3.1
[root@localhost ~]# yum remove git //刪除原有版本
[root@localhost ~]# git --version //再次查看版本號(hào)確認(rèn)已刪除成功
-bash: /usr/bin/git: No such file or directory
- 下載git源碼并解壓
[root@localhost ~]# wget https://www.kernel.org/pub/software/scm/git/git-2.9.3.tar.gz //下載git源碼
[root@localhost ~]# tar xf git-2.9.3.tar.gz //解壓git安裝包
[root@localhost ~]# mv git-2.9.3 /usr/src //移動(dòng)到/usr/src目錄下
- 編譯安裝
源碼的安裝一般由3個(gè)步驟組成:配置(configure)十嘿、編譯(make)、安裝(make install)岳锁。
[root@localhost git-2.9.3]# make configure
GEN configure
./configure prefix=/usr/local/git/
[root@localhost git-2.9.3]# ./configure prefix=/usr/local/git/ //配置git安裝路徑
[root@localhost git-2.9.3]# make && make install //編譯并且安裝
- 將git指令添加到bash中
[root@localhost ~]# vi /etc/profile //打開(kāi)文件
按下字母i鍵進(jìn)入編輯模式绩衷,在最后一行加入如下命令,加入后按Esc鍵退出編輯模式激率,并用:wq命令保存咳燕。
export PATH=$PATH:/usr/local/git/bin
[root@localhost ~]# source /etc/profile //讓profile配置文件立即生效
- 查看新版本
[root@localhost ~]# git --version //查看版本號(hào),安裝成功
git version 2.9.3
如果make的時(shí)候報(bào)錯(cuò):/bin/sh: msgfmt: command not found
則需要安裝git依賴包gettext-devel命令yum install gettext-devel
如果make的時(shí)候報(bào)錯(cuò):/bin/sh: autoconf: command not found
則需要yum install autoconf
[root@localhost git-2.9.3]# make configure
/bin/sh: autoconf: command not found
make: *** [configure] Error 127
[root@localhost git-2.9.3]# cd ~
[root@localhost ~]# yum install autoconf