centos7安装git

一、使用yum安装Git

1.查看 yum 源仓库的 Git 信息

使用yum info git查看

[root@localhost~]#  yum info git
Loaded plugins: fastestmirror, langpacks
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
Determining fastest mirrors
Available Packages
Name        : git
Arch        : x86_64
Version     : 1.8.3.1
Release     : 23.1.al7
Size        : 4.4 M
Repo        : updates/2.1903/x86_64
Summary     : Fast Version Control System
URL         : http://git-scm.com/
License     : GPLv2
Description : Git is a fast, scalable, distributed revision control system with an
            : unusually rich command set that provides both high-level operations
            : and full access to internals.
            : 
            : The git rpm installs the core tools with minimal dependencies.  To
            : install all git packages, including tools for integrating with other
            : SCMs, install the git-all meta-package.

yum源中的git版本比较老1.8.3.1,如果你依旧想安装他,继续执行下边操作。

2. 安装Git

yum install git

3.查看git版本

[root@localhost ~]# git --version
git version 1.8.3.1

4.卸载git

yum remove git

二、源码包安装Git

1.下载源码包

git源码包官方下载地址
https://mirrors.edge.kernel.org/pub/software/scm/git/

我下载的是git-2.39.0.tar.gz,下载目录放在了/usr/local

wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.39.0.tar.gz

2.解压源码包

tar -zxvf git-2.39.0.tar.gz

3.安装需要的依赖

# 安装依赖
yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker

4.检查是否安装过git

如果已经安装编译源码所需依赖的时候,yum自动帮你安装了git,这时候你需要先卸载这个旧版的git

yum -y remove git

5.编译安装

我选择安装在/usr/local/git目录下

cd /usr/local
mkdir git

# 进入文件目录
cd git-2.39.0

# 编译
make prefix=/usr/local/git all

# 安装git至/usr/local/git路径
make prefix=/usr/local/git install

6.配置环境变量

vim /etc/profile 
# 按i进入编辑模式,增加下方代码
export PATH=$PATH:/usr/local/git/bin
# 增加后按esc退出编辑模式,输入:wq保存退出
# 使配置文件生效
source /etc/profile

7.查看git是版本

[root@localhost ~]# git --version
git version 2.39.0
posted @ 2023-09-12 10:01  leepandar  阅读(140)  评论(0编辑  收藏  举报