前言

一般的平台通常都能通过自身的一个包管理工具去安装 git 的各个版本(包括当前官方最新版本),但是红帽系列通过 yum 安装却无法安装最新版本,而且都是很旧的版本,这种版本对许多新的命令以及特性都不支持,例如 switch 命令是 2.23 版本才发布的,在此之前的版本都没有,所以官方推荐像 CentOS 通过下载 git 源码包的方式去安装
RHEL and derivatives typically ship older versions of git. You can download a tarball and build from source, or use a 3rd-party repository such as the IUS Community Project to obtain a more recent version of git.
注意:直接 copy 下载地址,使用 wget 进行下载的时候,需要加上选项 --no-check-certificate,例如:
wget --no-check-certificate https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.9.5.tar.gz
否则会提示如下错误:
安装
1.安装前首先得安装依赖环境
yum install -y perl-devel
如果没有安装的话,会报如下错误:
make[1]: * [perl.mak] Error 2 make: * [perl/perl.mak] Error 2
2.下载源码包到 CentOS 服务器后进行解压
tar -zxf git-2.9.5.tar.gz cd git-2.9.5
3.执行如下命令进行编译安装
# 检查环境,配置安装路径 ./configure --prefix=/usr/local/git # 编译安装 make && make install
4.添加到系统环境变量
vim ~/.bashrc
文件末尾添加如下内容:
# git export PATH="/usr/local/git/bin:$PATH"
5.使配置生效
source ~/.bashrc
6.查看效果
git version
git version 2.9.5
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/220669.html原文链接:https://javaforall.net
