CentOS 如何安装 Git

前言

一般想要安装某一款软件包的时候通常会去查看官方文档
官网上对各个平台如何安装 git 进行了说明:https://git-scm.com/download/linux

在这里插入图片描述
一般的平台通常都能通过自身的一个包管理工具去安装 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.

安装源码包的地址如下:
https://mirrors.edge.kernel.org/pub/software/scm/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

否则会提示如下错误:

–2022-08-30 22:35:08-- https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.9.5.tar.gz
Resolving mirrors.edge.kernel.org (mirrors.edge.kernel.org)… 147.75.80.249, 2604:1380:4601:e00::3
Connecting to mirrors.edge.kernel.org (mirrors.edge.kernel.org)|147.75.80.249|:443… connected.
ERROR: cannot verify mirrors.edge.kernel.org’s certificate, issued by ‘/C=US/O=Let’s Encrypt/CN=R3’:
Issued certificate has expired.
To connect to mirrors.edge.kernel.org insecurely, use `–no-check-certificate’.

安装

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

  • 16
    点赞
  • 36
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值