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]$ echo 'export PATH=$HOME/git/libexec/git-core:$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

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值