做这个事的初衷
因为我的电脑上装的18.04版本的Ubuntu(毕竟是淘汰再利用的机器了,没装太高的版本,Ubuntu还是XUbuntu呢),直接使用apt-get install命令安装的git版本太低,所以直接去github上找到git的源码,通过编译安装的方法安装最新发布的git。
下载源码
下载地址:https://git-scm.com/
可能有点卡,多刷新几次。
选择tarball下载,下载完成后,直接tar命令解压。
生成配置脚本
解压后,执行make configure
命令,生成配置脚本。
执行之后遇到了下面的报错:
GEN configure
/bin/sh: 1: autoconf: not found
Makefile:2598: recipe for target 'configure' failed
make: *** [configure] Error 127
报错信息提示没有找到autoconf命令,由于没有安装autoconf包导致的。
执行apt-get install autoconf
命令,安装autoconf包。
autoconf安装完成后,继续执行make configure
命令,生成配置脚本。
完成后,没有出现报错信息,并且新生成了一个configure
文件。
执行./configure prefix=/opt/git
命令,运行刚刚生成的配置脚本。其中的prefix变量是git编译安装的路径。
这里执行配置脚本以后,会检查当前系统的配置情况,提示缺少哪些依赖库。
我也懒得看这些信息,后边编译时报错提示缺什么库再装就好了。
编译安装
执行make,开始编译。
遇到报错:
make: curl-config: Command not found
CC oss-fuzz/fuzz-commit-graph.o
In file included from oss-fuzz/fuzz-commit-graph.c:1:0:
./git-compat-util.h:399:10: fatal error: openssl/ssl.h: 没有那个文件或目录
#include <openssl/ssl.h>
^~~~~~~~~~~~~~~
compilation terminated.
Makefile:2719: recipe for target 'oss-fuzz/fuzz-commit-graph.o' failed
make: *** [oss-fuzz/fuzz-commit-graph.o] Error 1
提示找不到openssl/ssl.h
文件,典型的缺库,执行apt-get install libssl-dev
命令,装库.
继续make,报错:
make: curl-config: Command not found
CC oss-fuzz/fuzz-commit-graph.o
In file included from oss-fuzz/fuzz-commit-graph.c:1:0:
./git-compat-util.h:1495:10: fatal error: zlib.h: 没有那个文件或目录
#include <zlib.h>
^~~~~~~~
compilation terminated.
Makefile:2719: recipe for target 'oss-fuzz/fuzz-commit-graph.o' failed
make: *** [oss-fuzz/fuzz-commit-graph.o] Error 1
还是缺库,执行apt-get install zlib1g-dev
命令,装库。
再执行make
,OK了,编译顺利通过。
最后执行make install
命令,完成安装。
交叉编译到其他平台
留个问题。。。。日后解决再更。
Q&A
编译安装完成之后,git clone https的地址失败?
报错信息如下:
$ git clone https://github.com/LazyVim/starter.git
正克隆到 'starter'...
git:'remote-https' 不是一个 git 命令。参见 'git --help'。
一开始以为是环境变量没添加对,后来使用find
命令找遍了git的编译安装目录,也没找到git-remote-https
这个命令,推测是根本没编译出来这个命令。
没有编译出git-remote-https
命令的原因是系统中缺少libcurl
库的支持。
因此执行apt-get install libcurl4-openssl-dev
命令安装相关的依赖库,重新编译安装就可以了。