> 技术文档 > 如何在 RHEL 9 | Rocky Linux 9 上安装 Git ?

如何在 RHEL 9 | Rocky Linux 9 上安装 Git ?

如何在 RHEL 9 | Rocky Linux 9 上安装 Git ?

Git 是一个功能强大的版本控制系统,被开发人员广泛使用,用于管理源代码更改。

在本指南中,我们将向您介绍如何在 RHEL 9 或 Rocky Linux 9 上安装 Git 的过程。

通过 DNF 安装 Git

在 RHEL 9 或 Rocky Linux 9 上安装 Git 最简单的方法是使用默认的 DNF 包管理器。

  1. Update Your System

在安装任何新软件之前,最好将系统包更新到最新版本

$ sudo dnf update -y
  1. Install Git

现在,使用以下 dnf 命令安装 Git

$ sudo dnf install git -y

如何在 RHEL 9 | Rocky Linux 9 上安装 Git ?

  1. Verify the Installation

要检查 Git 是否成功安装,请使用以下命令验证版本

$ git --version

如何在 RHEL 9 | Rocky Linux 9 上安装 Git ?

源代码安装 Git

从源代码安装 Git 是另一种获取最新版本的方法版本或特定版本的 Git。这个方法是有用的,如果
通过包管理器提供的版本已过时。

  1. Install Development tools

在从源代码构建 Git 之前,需要使用以下 dnf 命令安装开发工具。

$ sudo dnf groupinstall \'Development Tools\' -y

如何在 RHEL 9 | Rocky Linux 9 上安装 Git ?

接下来,使用下面的命令安装其他必需的依赖项

$ sudo dnf install wget curl-devel perl-ExtUtils-MakeMaker gettext openssl-devel zlib-devel curl-devel expat-devel -y
  1. Download the Latest Git Source Code

访问 “https://mirrors.edge.kernel.org/pub/software/scm/git/” 下载最新的源代码

或者,您可以使用下面的命令直接下载它

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

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传
3) Extract the Downloaded Archive

使用 tar 命令提取 tar 文件

$ tar -xf git-2.47.0.tar.gz$ cd git-2.47.0
  1. Compile and Install Git

使用以下命令编译 Git 源代码

$ make configure$ ./configure --prefix=/usr

如何在 RHEL 9 | Rocky Linux 9 上安装 Git ?

$ sudo make all

如何在 RHEL 9 | Rocky Linux 9 上安装 Git ?

$ sudo make install

如何在 RHEL 9 | Rocky Linux 9 上安装 Git ?

  1. Verify the Installation

安装完成后,验证安装的 Git 版本

$ git --version

如何在 RHEL 9 | Rocky Linux 9 上安装 Git ?

配置 Git

在安装 Git 之后,设置您的用户名和电子邮件是必要的,此信息将与您的提交相关联。

  1. Set Your Username
$ git config --global user.name \"Pradeep Kumar\"
  1. Set Your Email Address
$ git config --global user.email \"info@linuxtechi.com\"

如何在 RHEL 9 | Rocky Linux 9 上安装 Git ?

  1. Verify the Configuration
$ git config --list

如何在 RHEL 9 | Rocky Linux 9 上安装 Git ?

我的开源项目

如何在 RHEL 9 | Rocky Linux 9 上安装 Git ?

  • course-tencent-cloud(酷瓜云课堂 - gitee仓库)
  • course-tencent-cloud(酷瓜云课堂 - github仓库)