1、检查是否安装了Git
[root@VM-0-16-centos /]# git --version
-bash: git: command not found
2、下载Git,如果是内网环境,可以先在本地下载好资源在上传到服务器
下载地址:https://mirrors.edge.kernel.org/pub/software/scm/git/
如果有外网权限,直接下载即可
# 命令:wget https://www.kernel.org/pub/software/scm/git/git-2.34.1.tar.gz
[root@VM-0-16-centos tmp]# wget https://www.kernel.org/pub/software/scm/git/git-2.34.1.tar.gz
--2022-01-04 11:53:47-- https://www.kernel.org/pub/software/scm/git/git-2.34.1.tar.gz
Resolving www.kernel.org (www.kernel.org)... 145.40.73.55, 2604:1380:40e1:4800::1
Connecting to www.kernel.org (www.kernel.org)|145.40.73.55|:443... connected.
ERROR: cannot verify www.kernel.org's certificate, issued by ‘/C=US/O=Let's Encrypt/CN=R3’:
Issued certificate has expired.
To connect to www.kernel.org insecurely, use `--no-check-certificate'.
# 提示网站没有证书警告的问题,可以使用不检查证书
# 开始下载
[root@VM-0-16-centos tmp]# wget https://www.kernel.org/pub/software/scm/git/git-2.34.1.tar.gz --no-check-certificate
--2022-01-04 11:56:35-- https://www.kernel.org/pub/software/scm/git/git-2.34.1.tar.gz
Resolving www.kernel.org (www.kernel.org)... 145.40.73.55, 2604:1380:40e1:4800::1
Connecting to www.kernel.org (www.kernel.org)|145.40.73.55|:443... connected.
WARNING: cannot verify www.kernel.org's certificate, issued by ‘/C=US/O=Let's Encrypt/CN=R3’:
Issued certificate has expired.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.34.1.tar.gz [following]
--2022-01-04 11:56:37-- https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.34.1.tar.gz
Resolving mirrors.edge.kernel.org (mirrors.edge.kernel.org)... 147.75.95.133, 2604:1380:3000:1500::1
Connecting to mirrors.edge.kernel.org (mirrors.edge.kernel.org)|147.75.95.133|:443... connected.
WARNING: cannot verify mirrors.edge.kernel.org's certificate, issued by ‘/C=US/O=Let's Encrypt/CN=R3’:
Issued certificate has expired.
HTTP request sent, awaiting response... 200 OK
3、查看并解压下载的安装包git-2.34.1.tar.gz
# 解压命令:tar -zxvf git-2.34.1.tar.gz
[root@VM-0-16-centos tmp]# ll
total 153552
-rw-r--r-- 1 root root 10425720 Nov 25 03:54 git-2.34.1.tar.gz
-rw-r--r-- 1 root root 146799982 Jan 4 11:16 jdk-8u311-linux-x64.tar.gz
# 开始解压
[root@VM-0-16-centos tmp]# tar -zxvf git-2.34.1.tar.gz
# 解压完成 git-2.34.1
drwxrwxr-x 26 root root 20480 Nov 25 03:29 git-2.34.1
-rw-r--r-- 1 root root 10425720 Nov 25 03:54 git-2.34.1.tar.gz
4、安装编译Git时需要的包
这里也是如果没有外网,可以在本地下载好rpm安装包,具体下载地址很多,我这里放了3个地址,根据自己的环境选择下载:
http://mirrors.163.com/centos/7/os/x86_64/Packages/
https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/
http://rpmfind.net/linux/rpm2html/search.php
# 输入下面这个命令,它会将当前文件夹下所有的rpm包进行强制安装。
rpm -ivh *.rpm --force --nodeps
如果有外网权限直接下载即可
yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
yum install gcc perl-ExtUtils-MakeMaker
5、删除已有的Git
yum remove git
6、编译安装
# 进入根目录:cd /usr/local/src/git-2.9.4
# 安装到/usr/local/git目录:./configure --prefix=/usr/local/git
# 编译安装:make && make install
# 将git安装到/usr/local/git
[root@VM-0-16-centos git-2.34.1]# ./configure --prefix=/usr/local/git
configure: Setting lib to 'lib' (the default)
configure: Will try -pthread then -lpthread to enable POSIX Threads.
configure: CHECKS for site configuration
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether gcc accepts -g... yes
checking for gcc option to enable C11 features... -std=gnu11
checking for stdio.h... yes
checking for stdlib.h... yes
# 编译安装,知道安装完成
[root@VM-0-16-centos git-2.34.1]# make && make install
GIT_VERSION = 2.34.1
* new build flags
CC fuzz-commit-graph.o
CC fuzz-pack-headers.o
CC fuzz-pack-idx.o
CC daemon.o
* new link flags
......
7、创建软链接
ln -s /usr/local/git/bin/* /usr/local/bin/
8、检查是否安装成功
[root@VM-0-16-centos git-2.34.1]# git --version
git version 2.34.1
Git已成功安装。