Centos7安裝(配置)Git

環境:Centos7、JDK1.8(已經安裝成功)、MySQL5.7(已經安裝成功)、Git
步驟:
  1.下載Git源碼
  2.移除舊版本
  3.安裝&配置

1.下載Git源碼

  手動下載下來在上傳到服務器上面,當然也可以通過wget直接下載到服務器上。這裏使用wget直接下載git到服務器上。

https://github.com/git/git/releases

https://www.kernel.org/pub/software/scm/git/

2.移除舊版本git

  Centos7自帶git x.x.x.x版本,安裝新版本之前需要使用yum remove git卸載(安裝後卸載也可以)。

#可能輸入git --version顯示'bash: git: 未找到命令...' 則接着往下執行即可

[root@Git ~]# git --version    ## 查看自帶的版本

git version 1.8.3.1

[root@Git ~]# yum remove git   ## 移除原來的版本

3.安裝&配置

(1).安裝依賴包

  安裝依賴包的時候首先需要配置yum源,如果配置了則請忽略。https://www.cnblogs.com/HOsystem/p/14033644.html

[root@Git ~]# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel -y

[root@Git ~]# yum install gcc-c++ perl-ExtUtils-MakeMaker -y

(2).下載&解壓

#進入到src中,把git源碼包下載到該地方

[root@Git src]# cd /usr/src

 

#通過wget下載git-2.7.3版本源碼,若wget不存在,則通過yum install wget安裝wget

[root@Git src]# wget https://www.kernel.org/pub/software/scm/git/git-2.7.3.tar.gz

 

#解壓下載源碼包

[root@Git src]# tar -zxvf git-2.7.3.tar.gz

 

(3).編譯安裝

#進入解壓的git目錄

[root@Git src]# cd git-2.7.3

 

#若出現錯誤,接着往下看 執行yum install autoconf -y

[root@Git src]# make configure

 

[root@Git src]# ./configure --prefix=/usr/git ##配置目錄

 

[root@Git src]# make profix=/usr/git

 

[root@Git src]# make install

  問題:'make configure'出現錯誤'/bin/sh:autoconf:未找到命令'

  解決方法:

  執行'yum install autoconf -y'.

[root@Git src]# yum install autoconf -y

 

(4).環境變量

[root@Git ~]# echo "export PATH=$PATH:/usr/git/bin" >> /etc/profile

[root@Git ~]# source /etc/profile

(5).檢查版本

#若顯示git version 1.8.3.1,則未remove成功。接着往下看解決方法

[root@Git git-2.7.3]# git --version

git version 2.7.3

問題:輸入'git --verison'若顯示git version 1.8.3.1,則未remove成功.只需要重新執行以下即可。

 

[root@localhost git-2.7.3]# yum remove git

[root@localhost git-2.7.3]# echo "export PATH=$PATH:/usr/git/bin" >> /etc/profile

[root@localhost git-2.7.3]# source /etc/profile

[root@localhost git-2.7.3]# git --version

git version 2.7.3

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章