如题

如果不想看笔者的安装过程(看安装过程,可以知道哪一个问题如何解决),直接按照以下步骤执行即可。

安装的正确姿势

第一种安装方案:不安装 git 文档(推荐)

安装依赖

1
yum install -y curl-devel zlib-devel gcc autoconf

下载最新版的 git 源码:

安装 git

1
2
3
make configure
./configure --prefix=/usr # 配置目录
make && make install

第二种安装方案:安装 git 的同时,安装 git 文档

安装依赖

1
2
3
4
yum install -y curl-devel perl-XML-SAX.noarch texinfo perl openjade dh-autoreconf autoconf libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev asciidoc xmlto docbook2x
wget http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/d/docbook2X-0.8.8-17.el7.x86_64.rpm
rpm -ivh docbook2X-0.8.8-17.el7.x86_64.rpm
ln -s /usr/bin/db2x_docbook2texi /usr/bin/docbook2x-texi

安装 git

以下是在 CentOS 7.5 上安装,并记录了详细过程

下载最新版

到官方 github 下载最新的 git release 版本
本教程下载的是 git-2.17.1 版本,下载之后,按照官方教程,依次执行以下命令。

1
2
3
4
5
6
7
8
9
10
11
wget https://github.com/git/git/archive/v2.17.1.tar.gz
yum install -y dh-autoreconf autoconf libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev asciidoc xmlto docbook2x
tar -xzvf v2.17.1.tar.gz
cd git-2.17.1/
make configure
./configure --prefix=/usr # 配置目录
make profix=/usr/git
# 安装遇到问题,需要 docbook2x 依赖,请继续往下阅读。
make all doc info
# 先解决上一步的问题再执行。
make install install-doc install-html install-info

安装过程遇到的问题

实际上,按照官方教程,docbook2x 并没有被安装上。同时,还需要安装别的依赖。

autoconf: command not found

1
2
3
4
[root@centOS7BasicForTest git-2.17.1]# make configure
GEN configure
/bin/sh: autoconf: command not found
make: *** [configure] Error 127

安装依赖:yum install -y autoconf

docbook2x-texi: command not found

1
2
3
4
5
6
make all doc info
...
/bin/sh: line 1: docbook2x-texi: command not found
make[1]: *** [user-manual.texi] Error 127
make[1]: Leaving directory `/root/soft/git-2.18.0/Documentation'
make: *** [info] Error 2
  1. 安装时,提示找不到 docbook2X

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    [root@centOS7BasicForTest git-2.17.1]# yum install -y asciidoc xmlto docbook2X
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    * base: mirrors.aliyun.com
    * extras: mirrors.aliyun.com
    * updates: mirrors.aliyun.com
    Package asciidoc-8.6.8-5.el7.noarch already installed and latest version
    Package xmlto-0.0.25-7.el7.x86_64 already installed and latest version
    No package docbook2X available.
    Nothing to do
  2. 下载 docbook2X 的 rpm 包来安装

    1
    2
    3
    4
    5
    6
    7
    8
    wget http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/d/docbook2X-0.8.8-17.el7.x86_64.rpm
    [root@centOS7BasicForTest ~]# rpm -ivh docbook2X-0.8.8-17.el7.x86_64.rpm
    warning: docbook2X-0.8.8-17.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
    error: Failed dependencies:
    /usr/bin/sgml2xml is needed by docbook2X-0.8.8-17.el7.x86_64
    openjade is needed by docbook2X-0.8.8-17.el7.x86_64
    perl(XML::SAX::ParserFactory) is needed by docbook2X-0.8.8-17.el7.x86_64
    texinfo is needed by docbook2X-0.8.8-17.el7.x86_64
  3. 安装 docbook2X 的依赖

    1
    2
    3
    4
    5
    yum install -y texinfo perl openjade
    [root@centOS7BasicForTest ~]# rpm -ivh docbook2X-0.8.8-17.el7.x86_64.rpm
    warning: docbook2X-0.8.8-17.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
    error: Failed dependencies:
    perl(XML::SAX::ParserFactory) is needed by docbook2X-0.8.8-17.el7.x86_64
  4. 继续安装 docbook2X 依赖

    1
    2
    3
    4
    5
    6
    yum install -y perl-XML-SAX.noarch
    [root@centOS7BasicForTest ~]# rpm -ivh docbook2X-0.8.8-17.el7.x86_64.rpm
    warning: docbook2X-0.8.8-17.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
    Preparing... ################################# [100%]
    Updating / installing...
    1:docbook2X-0.8.8-17.el7 ################################# [100%]

依然有错误

1
/bin/sh: line 1: docbook2x-texi: command not found

执行 ln 链接 db2x_docbook2texi 为 docbook2x-texi

1
2
3
4
[root@centOS7BasicForTest git-2.17.1]# find / -name db2x_docbook2texi
/usr/bin/db2x_docbook2texi
[root@centOS7BasicForTest git-2.17.1]# cd /usr/bin/
[root@centOS7BasicForTest bin]# ln -s db2x_docbook2texi docbook2x-texi

再次依次执行编译安装,没再报错。

1
2
3
4
make configure
./configure --prefix=/usr
make all doc info # 漫长的等待...
make install install-doc install-html install-info

检查 git 版本

1
2
[root@centOS7BasicForTest git-2.17.1]# git --version
git version 2.17.1

安装官方教程

  1. 官方英文参考
  2. 官方中文参考

配置 git 作为服务端

请移步:CentOS 7.5 借助 Gitolite 管理 Git 项目

后记

no acceptable C compiler found in $PATH

解决:

1
yum -y install gcc

zlib.h: No such file or directory

1
2
3
4
5
6
7
8
9
10
[root@localhost git-2.24.1]# make && make install
* new build flags
CC fuzz-commit-graph.o
In file included from commit-graph.h:7:0,
from fuzz-commit-graph.c:1:
cache.h:21:18: fatal error: zlib.h: No such file or directory
#include <zlib.h>
^
compilation terminated.
make: *** [fuzz-commit-graph.o] Error 1

解决:

1
yum install -y zlib-devel

  • 2019-08-19 再一次需要安装 git,这次偷了个懒,没有安装 git 文档(make all doc info 换成了 makemake install install-doc install-html install-info 换成了 make install),遇到了问题,这次的安装过程如下:
    1
    2
    3
    make configure
    ./configure --prefix=/usr # 配置目录
    make && make install

这样安装不存在上文提到的诸多依赖问题,也能 clone gitee 上的项目。但是在 clone github 上的项目,就遇到了下面的错误。

fatal: unable to find remote helper for ‘https’

1
2
3
[utomcat@localhost ~]$ git clone https://github.com/ant-design/ant-design-pro --depth=1 /home/utomcat/other/ant-design-pro-ts
Cloning into '/home/utomcat/other/ant-design-pro-ts'...
fatal: unable to find remote helper for 'https'

遇到这个错误,搜索了一下,网上说什么的都有,原因千奇百怪,在我的虚拟机上,就是没安装全。
解决办法就按照前面的步骤安装(参考了官网的安装说明)。

fatal: unable to find remote helper for ‘http’

错误原因同上,只是在 clone github 上的项目时,用的 http 协议而已。

再一次后记 2019-09-01

今天因为配置 gitolite,在一台新的虚拟机上操作,按照之前写的文档安装 git 的最新版 2.23.0,安装完成之后:

  • 执行 git clone https://github.com/sitaramc/gitolite,提示:fatal: unable to find remote helper for 'https'
  • 执行 git clone http://github.com/sitaramc/gitolite,提示:fatal: unable to find remote helper for 'http'

怀疑新版本与我之前使用的版本有差异,于是又重新安装了 2.17.1,问题依旧,我开始怀疑这个错误的原因并不一定是没有安装 doc 导致,至于之前的版本安装 doc 之后就好了,有点丈二和尚摸不着头脑,不过,可能跟下面的提示信息有关,是在执行 make all doc info 时比较可疑的信息:

1
2
3
4
5
6
7
8
9
make[2]: Leaving directory `/root/soft/git-2.17.1'
DB2TEXI user-manual.texi
docbook2texi:/book: no description for directory entry
MAKEINFO git.info
user-manual.texi:15: warning: empty menu entry name in `* : idm47715126121840.'
user-manual.texi:141: warning: @unnumbered missing argument
DB2TEXI gitman.texi
MAKEINFO gitman.info
make[1]: Leaving directory `/root/soft/git-2.17.1/Documentation'

以下是安装 2.19.1 时的可疑提示信息:

1
2
3
4
5
6
7
docbook2texi:/book: no description for directory entry
MAKEINFO git.info
user-manual.texi:15: warning: empty menu entry name in `* : idm47678928261200.'
user-manual.texi:141: warning: @unnumbered missing argument
DB2TEXI gitman.texi
utf8 "\x89" does not map to Unicode at /usr/share/perl5/vendor_perl/XML/SAX/PurePerl/Reader/Stream.pm line 37.
MAKEINFO gitman.info

在网上又参考了好多文章,最后问题解决。

在安装之前,需要先安装 curl-devel,执行命令 yum install -y curl-devel 安装,之后再重新安装 git,然后世界就清静了~~

结论

安装 git 的最新(简)步骤:

  1. 安装依赖

    1
    yum install -y curl-devel zlib-devel gcc autoconf
  2. 下载最新版的 git 源码:

  3. 安装 git
    1
    2
    3
    make configure
    ./configure --prefix=/usr # 配置目录
    make && make install