CentOS安裝git

來源:互聯網
上載者:User

標籤:

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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.