Git安装(源码编译安装)
本文主要讲述一下Git通过源码方式进行安装的步骤。如果不想折腾,直接下载Git已编译好的软件包安装即可,进入官网可以直接查看其安装命令或软件包地址,官网地址点击[这里](https://git-scm.com/downloads)。
1. 安装依赖
sudo apt-get install dh-autoreconf libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev
2. 下载源码包
- 可以从 Kernel.org 网站获取,网址为 https://www.kernel.org/pub/software/scm/git
- 或从 GitHub 网站上的镜像来获得,网址为 https://github.com/git/git/releases
比如我下载一个2.28.0版本的源码包,点击这里下载就可以。
命令行下载:
wget https://www.kernel.org/pub/software/scm/git/git-2.28.0.tar.gz
https://www.kernel.org/pub/software/scm/git/
3. 编译安装
tar -zxf git-2.28.0.tar.gz
cd git-2.28.0
make configure
./configure --prefix=/usr/local/git
make
make install
以上注意:<font style="color:rgb(85, 85, 85);background-color:rgb(238, 238, 238);">--prefix=/usr/local/git</font>参数是定义编译安装后的Git位置是在<font style="color:rgb(85, 85, 85);background-color:rgb(238, 238, 238);">/usr/local/git</font>目录。
只要安装不出错,执行<font style="color:rgb(85, 85, 85);background-color:rgb(238, 238, 238);">git</font>命令将可以输出信息。
4. 安装问题
若执行make时报错:
* new build flags
CC credential-store.o
In file included from /usr/include/openssl/x509.h:22:0,
from /usr/include/openssl/ssl.h:20,
from git-compat-util.h:283,
from cache.h:4,
from credential-store.c:1:
/usr/include/openssl/ec.h: In function ‘DEPRECATEDIN_1_2_0’:
/usr/include/openssl/ec.h:274:1: error: expected declaration specifiers before ‘DEPRECATEDIN_1_2_0’
/usr/include/openssl/ec.h:261:1: error: old-style parameter declarations in prototyped function definition
DEPRECATEDIN_1_2_0(int EC_GROUP_set_curve_GFp(EC_GROUP *group, const BIGNUM *p,
^~~~~~~~~~~~~~~~~~
credential-store.c:194:1: error: expected ‘{’ at end of input
}
在配置时指定对应的openssl依赖位置,因为openssl也是源码方式安装,但是这个位置Git安装程序不认识。
./configure --prefix=/usr/local/git --with-openssl=/usr/local/openssl

浙公网安备 33010602011771号