1. 下載git, 下載地址, 我下載的是git-2.9.5.tar.gz
[root@localhost cocosum.cn]# ls
git-2.9.5.tar.gz
2. 解壓
[root@localhost cocosum.cn]# sudo zxvf git-2.9.5
3. 安裝依賴
[root@localhost cocosum.cn]# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker
4. 編譯
[root@localhost cocosum.cn]# cd git-2.9.5/
[root@localhost git-2.9.5]#
[root@localhost git-2.9.5]# make prefix=/usr/local/git all
5. 安裝
[root@localhost git-2.9.5]# make prefix=/usr/local/git install
6. 配置環境變量
[root@localhost git-2.9.5]# vi /etc/profile
加入下面環境變量:
export PATH=$PATH:/usr/local/git/bin
7. 使配置生效
[root@localhost git-2.9.5]# source /etc/profile
8. 檢查Git版本
[root@localhost git-2.9.5]# git --version
git version 2.9.5
上面參考原文:
其實可以不一定要安裝在/usr/local/ 下面,也可以自己定義,
我自己安裝在/opt/git-2.9.5/install/, 編譯的時候把路徑改掉就行了(安裝同編譯路徑),
這種自定義路徑用git --version 無法獲取。下面方式可以獲取:
我的編譯路徑和安裝路徑是:
[root@localhost git-2.9.5]# ls /opt/git-2.9.5/install/git/
bin libexec share
查看我安裝的git版本
[root@localhost git-2.9.5]# /opt/git-2.9.5/install/git/bin/git --version
git version 2.9.5
9. 卸載Git, 直接刪除你安裝的路徑就OK了
[root@localhost git-2.9.5]# cd /usr/local/
[root@localhost local]# ls
bin etc games git include lib lib64 libexec sbin share src
[root@localhost local]# rm -rf git
還有一種安裝方式: yum 安裝
# 檢查
[root@VM_0_3_centos ~]# git --vserion
-bash: git: command not found
[root@VM_0_3_centos ~]# yum -y install git
Loaded plugins: fastestmirror, langpacks
Repository epel is listed more than once in the configuration
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
............
............
............
Installed:
git.x86_64 0:1.8.3.1-20.el7
Dependency Installed:
perl-Git.noarch 0:1.8.3.1-20.el7
Complete!
[root@VM_0_3_centos ~]# git --version
git version 1.8.3.1
[root@VM_0_3_centos ~]#