Git:源碼安裝版本控制工具Git

Git:源碼安裝版本控制工具Git

1.下載源碼

https://github.com/git/git
https://www.git-scm.com/download/
https://mirrors.edge.kernel.org/pub/software/scm/git/

我下載的源碼是:

https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.20.1.tar.gz

2.開始安裝

[test1280@localhost ~]$ ll
total 7776
-rw-r--r--. 1 test1280 test1280 7962304 Feb 21 03:37 git-2.20.1.tar.gz
[test1280@localhost ~]$ tar zxf git-2.20.1.tar.gz 
[test1280@localhost ~]$ ll
total 7796
drwxrwxr-x. 25 test1280 test1280   20480 Dec 14 20:24 git-2.20.1
-rw-r--r--.  1 test1280 test1280 7962304 Feb 21 03:37 git-2.20.1.tar.gz
[test1280@localhost ~]$ cd git-2.20.1
[test1280@localhost git-2.20.1]$

Q1)

[test1280@localhost git-2.20.1]$ make configure
GIT_VERSION = 2.20.1
    GEN configure
/bin/sh: autoconf: command not found
make: *** [configure] Error 127

在root權限中安裝autoconf工具

[root@localhost ~]# yum install -y autoconf

重新生成configure文件

[test1280@localhost git-2.20.1]$ make configure
    GEN configure
[test1280@localhost git-2.20.1]$ ll configure
-rwxrwxr-x. 1 test1280 test1280 383824 Feb 21 12:05 configure

Q2)

執行configure文件生成makefile,並嘗試編譯

[test1280@localhost git-2.20.1]$ ./configure --prefix=$HOME/git && make
configure: Setting lib to 'lib' (the default)
configure: Will try -pthread then -lpthread to enable POSIX Threads.
…
config.status: executing config.mak.autogen commands
    * new build flags
    CC fuzz-pack-headers.o
In file included from packfile.h:4,
                 from fuzz-pack-headers.c:1:
cache.h:20:18: warning: zlib.h: No such file or directory
In file included from packfile.h:4,
                 from fuzz-pack-headers.c:1:
cache.h:22: error: expected specifier-qualifier-list before 鈥榸_stream鈥
make: *** [fuzz-pack-headers.o] Error 1

在root權限中安裝zlib-devel

[root@localhost ~]# yum install -y zlib-devel

Q3)

重新編譯並嘗試安裝(安裝目錄:執行configure時prefix指定的目錄:$HOME/git)

[test1280@localhost git-2.20.1]$ make && make install
    CC fuzz-pack-headers.o
    CC fuzz-pack-idx.o
	…
    BUILTIN git-whatchanged
    SUBDIR git-gui
GITGUI_VERSION = 0.21.GITGUI
    * new locations or Tcl/Tk interpreter
    GEN git-gui
    INDEX lib/
    * tclsh failed; using unoptimized loading
    MSGFMT    po/bg.msg make[1]: *** [po/bg.msg] Error 127
make: *** [all] Error 2

通過設置configure執行參數【- -without-tcltk】,重新生成makefile

[test1280@localhost git-2.20.1]$ ./configure --prefix=$HOME/git --without-tcltk
configure: Setting lib to 'lib' (the default)
configure: Will try -pthread then -lpthread to enable POSIX Threads.
configure: CHECKS for site configuration
……
config.status: creating config.mak.autogen
config.status: executing config.mak.autogen commands
[test1280@localhost git-2.20.1]$

Q4)

重新編譯並嘗試安裝

[test1280@localhost git-2.20.1]$ make && make install
    * new build flags
    CC fuzz-pack-headers.o
    CC fuzz-pack-idx.o
	……
    SUBDIR templates
    MSGFMT po/build/locale/bg/LC_MESSAGES/git.mo
/bin/sh: msgfmt: command not found
make: *** [po/build/locale/bg/LC_MESSAGES/git.mo] Error 127

在root權限中安裝gettext-devel開發包

[root@localhost ~]# yum install -y gettext-devel

Q5)

重新編譯並嘗試安裝

[test1280@localhost git-2.20.1]$ make && make install
    SUBDIR templates
    MSGFMT po/build/locale/bg/LC_MESSAGES/git.mo
4187 translated messages.
……
	done && \
	./check_bindir "z$bindir" "z$execdir" "$bindir/git-add"
[test1280@localhost git-2.20.1]$ 

安裝成功!


[test1280@localhost git-2.20.1]$ cd $HOME/git/bin && ll
total 53984
-rwxr-xr-x. 127 test1280 test1280 12059865 Feb 21 12:22 git
-rwxr-xr-x.   2 test1280 test1280   162745 Feb 21 12:22 git-cvsserver
-rwxr-xr-x. 127 test1280 test1280 12059865 Feb 21 12:22 git-receive-pack
-rwxr-xr-x.   2 test1280 test1280  6862055 Feb 21 12:22 git-shell
-rwxr-xr-x. 127 test1280 test1280 12059865 Feb 21 12:22 git-upload-archive
-rwxr-xr-x. 127 test1280 test1280 12059865 Feb 21 12:22 git-upload-pack

修改~/.bash_profile文件,將$HOME/git/bin加入PATH目錄

[test1280@localhost bin]$ echo 'export PATH=$HOME/git/bin:$PATH' >> ~/.bash_profile

使環境變量生效

[test1280@localhost bin]$ source ~/.bash_profile
[test1280@localhost bin]$ which git
~/git/bin/git

查看新安裝的Git版本

[test1280@localhost bin]$ git --version
git version 2.20.1

參考:

1.https://github.com/git/git/blob/master/INSTALL
2.https://www.cnblogs.com/grimm/p/5368777.html
3.https://blog.csdn.net/wanghaihao_1/article/details/44034101
4.http://blog.sciencenet.cn/blog-728999-846435.html
5.https://blog.csdn.net/w_yunlong/article/details/70047050

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