[Linux] 在 CentOS 7 上安裝最新版的 Git

[Linux] 在 CentOS 7 上安裝最新版的 Git

在 CentOS 7 上裝好 VSCode 之後,

VSCode 就出現了一個訊息,說 Git 的版本要在 2.0 以上~

本來也懶得管它,後來發現好像 VSCode 上的 Git 功能有些問題,

想想可能還是得來升級一下 Git 囉~

 

看一下 CentOS 7 現在的 Git 版本,是 1.8.3.1:

testuser@localhost ~ $ git --version
git version 1.8.3.1

 

這已經是 Yum Repository 上的最新版本:

testuser@localhost ~ $ yum info git

Installed Packages
Name        : git
Arch        : x86_64
Version     : 1.8.3.1
Release     : 20.el7
Size        : 22 M
Repo        : installed
From repo   : updates
Summary     : Fast Version Control System
URL         : http://git-scm.com/
License     : GPLv2
Description : Git is a fast, scalable, distributed revision control system with an
            : unusually rich command set that provides both high-level operations
            : and full access to internals.
            :
            : The git rpm installs the core tools with minimal dependencies.  To
            : install all git packages, including tools for integrating with other
            : SCMs, install the git-all meta-package.

 

然而,Git 早就已經到 2.x 版本,

CentOS 的套件更新真的很慢…

 

查了一下,有人推薦可以用 IUS Community repositories

這個 IUS (Inline with Upstream Stable) 專案的目標,

就是提供 RHEL 和 CentOS 平台上,最新的軟體套件~

 

執行下面的指令,先把 CentOS 7 附的舊版 git 移掉:

sudo yum remove git

 

安裝 IUS 提供的 RPM 後,就會在系統中加入 IUS 的 Yum Repository,

這時就可以安裝 git2u 套件(注意不是 git 套件):

sudo rpm -U https://centos7.iuscommunity.org/ius-release.rpm
sudo yum install git2u

 

git2u 套件裝的也是 Git,

只是是最新版本的 Git,像現在就是 2.16.5:

testuser@localhost ~ $ git --version

git version 2.16.5

 

這樣子 VSCode 就不會再抱怨 Git 版本太舊囉~

 

參考資料:serverfault: Install a newer version of Git on CentOS 7

(本頁面已被瀏覽過 6,232 次)

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料