標籤:
Method #1 » 用yum源安裝:
[[email protected] ~]# sudo yum install git
查看安裝的git的版本號碼:
[[email protected] ~]# git --versiongit version 1.8.3.1
但yum源中安裝的git版本是1.8.3.1,太老了。
Method #2 » 下載git源碼,編譯安裝:
1.更新安裝源:
[[email protected] ~]# yum update
2.安裝git相關的依賴包:
[[email protected] ~]# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker
3.到git官網查看最新的版本為2.8.1:
https://git-scm.com/download/
4.下載git源碼並解壓:
[[email protected] ~]# wget https://github.com/git/git/archive/v2.8.1.zip[[email protected] ~]# unzip v2.8.1.zip[[email protected] ~]# cd git-2.8.1
5.編譯安裝到“/usr/local/git”目錄下:
[[email protected] ~]#make prefix=/usr/local/git all[[email protected] ~]#make prefix=/usr/local/git install
此時,使用git --version 查看git版本,發現仍然是1.8.3.1版本。這是因為它預設使用了"/usr/bin"下的git。
[[email protected] ~]# git --versiongit version 1.8.3.1
接著查看git所在的路徑:
[[email protected] git-2.8.1]# whereis gitgit: /usr/bin/git /usr/share/man/man1/git.1.gz
6.設定環境變數:
把編譯安裝的git路徑放到環境變數裡,讓它替換"/usr/bin"下的git。為此我們可以修改“/etc/profile”檔案(或者/etc/bashrc檔案),在檔案的最後一行(即77行)添加“export PATH=/usr/local/git/bin:$PATH”。
[[email protected] ~]# vim /etc/profile
儲存修改:
[[email protected] ~]# source /etc/profile
再次查看git的版本號碼是2.8.1:
[[email protected] ~]# git --versiongit version 2.8.1
CentOS安裝git