make Git on CentOS 5.6

Git 是個很棒的分散式版本控制系統,在 Debian, Ubuntu 只需一行指令就可無痛安裝,而 CentOS 的套件庫似乎還未收錄到 Git,這對開始使用 Git 管理機器的凍仁有些意外,只要預裝一下 gcc 自己編就搞定了!


1. 下載 git-$VERSION.tar.gz (本文使用的版本為 1.7.9.4)。

2. 解壓縮。
root@CentOS:~$ tar zxvf git-1.7.9.4.tar.gz [Enter]

3. 切換至 git-$VERSION 目錄底下。
root@CentOS:~$ cd git-1.7.9.4 [Enter]

4. 設定編譯環境 (自訂安裝目錄為 /usr/local/git)。
root@CentOS:~$ ./configure --prefix=/usr/local/git [Enter]

5. 編譯。
root@CentOS:~$ make && make install [Enter]

6. 將 git 執行檔連結至 /usr/local/bin/。
root@CentOS:~$ ln -s /usr/local/git/bin/git* /usr/local/bin/ [Enter]

7. 測試。
root@CentOS:~$ git [Enter]
usage: git [--version] [--exec-path[=]] [--html-path] [--man-path] [--info-path]
           [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
           [--git-dir=] [--work-tree=] [--namespace=]
           [-c name=value] [--help]
            []

The most commonly used git commands are:
   add        Add file contents to the index
   bisect     Find by binary search the change that introduced a bug
   branch     List, create, or delete branches
   checkout   Checkout a branch or paths to the working tree
   clone      Clone a repository into a new directory
   commit     Record changes to the repository
   diff       Show changes between commits, commit and working tree, etc
   fetch      Download objects and refs from another repository
   grep       Print lines matching a pattern
   init       Create an empty git repository or reinitialize an existing one
   log        Show commit logs
   merge      Join two or more development histories together
   mv         Move or rename a file, a directory, or a symlink
   pull       Fetch from and merge with another repository or a local branch
   push       Update remote refs along with associated objects
   rebase     Forward-port local commits to the updated upstream head
   reset      Reset current HEAD to the specified state
   rm         Remove files from the working tree and from the index
   show       Show various types of objects
   status     Show the working tree status
   tag        Create, list, delete or verify a tag object signed with GPG

See 'git help ' for more information on a specific command.

恭喜您,現在可以在 CentOS 上使用 git 了,是不是很棒啊!

# 近來在下啟用了減重大作戰,相對的整理筆記的時間也少了,不過能在第一週就瘦了 3.5kg 真的是很開心呢,紀錄一下囉!

2012-04-17


在編譯 Git 之前還需從安裝光碟補完 curlcurl-devel 兩套件,而安裝 curl-devel 時得一同補上其相依套件 (e2fsprogs-devel, keyutils-libs-devel, krb5-devel, libidn-devel, libselinux-devel, libsepol-devel, openssl-devel, zlib-devel)。

延伸閱讀:
Debian Linux 架設使用 SSH 存取 的 Git Server - Tsung's Blog

相關連結:
在 CentOS 5.5 上使用 yum 安装 Git - SoniTech

資料來源:
Downloads - git-core - Git - the stupid content tracker - Google Project Hosting
Simple Install of Git on Leopard

留言

  1. 印象中有 rpm 可以裝吧 O_Oa

    回覆刪除
    回覆
    1. 小聲說:CentOS 的兄弟「RHEL」不見得有.. :P

      刪除
    2. 話說後來有很多時候回頭看這篇文,都是因為 CentOS 內建的 Git 版本過舊,才這樣自己編 Git。

      刪除
  2. 9 個月後,Git 已經來到 1.8.0.2,這次一樣先裝上 curl-devel.x86_64 後即可正常編譯。

    root>
    # yum install curl-devel.x86_64
    # ./configure --prefix=/usr/local/git
    # make && make install

    回覆刪除
    回覆
    1. 還需手動補 PATH。
      # ln -s /usr/local/git/bin/* /usr/local/bin/

      刪除
  3. 因已無法在 macOS v10.11.6 使用 homebrew 正常安裝 Git,故自行下載 git-2.28.0.tar.gz 進行編譯。

    ```
    $ wget https://www.kernel.org/pub/software/scm/git/git-2.28.0.tar.gz
    $ tar jxvf git-2.28.0.tar.gz
    $ ./configure --prefix=/usr/local/git
    $ make && sudo make install
    ```

    之後上 GitHub 找 v2.28.0 的 git-completion.bash。

    ```
    $ wget https://raw.githubusercontent.com/git/git/v2.28.0/contrib/completion/git-completion.bash
    ```

    更名為 git。

    ```
    $ mv git-completion.bash git
    ```

    放置於 bash-completion 底下。

    ```
    $ mv git /usr/local/Cellar/bash-completion@2/2.7/share/bash-completion/completions/
    ```

    重新連結 bash-completion。

    ```
    $ brew unlink bash-completion
    $ brew link bash-completion
    ```

    DONE.

    > 在 Mac OS X 用 Bash 安裝 git auto complete | Chris 技術筆記
    > - https://dwatow.github.io/2018/09-21-git-cmd-auto-complete/

    回覆刪除

張貼留言

喜歡這篇文章嗎?歡迎在底下留言讓凍仁知道。😉

Popular Articles

MySQL 語法匯整