Git 是一個功能強大的版本控制系統,被開發人員廣泛使用,用於管理源代碼更改。
在本指南中,我們將向您介紹如何在 RHEL 9 或 Rocky Linux 9 上安裝 Git 的過程。
通過 DNF 安裝 Git
在 RHEL 9 或 Rocky Linux 9 上安裝 Git 最簡單的方法是使用默認的 DNF 包管理器。
1) Update Your System
在安裝任何新軟件之前,最好將系統包更新到最新版本
$ sudo dnf update -y
2) Install Git
現在,使用以下 dnf 命令安裝 Git
$ sudo dnf install git -y
3) Verify the Installation
要檢查 Git 是否成功安裝,請使用以下命令驗證版本
$ git --version
源代碼安裝 Git
從源代碼安裝 Git 是另一種獲取最新版本的方法版本或特定版本的 Git。這個方法是有用的,如果
通過包管理器提供的版本已過時。
1) Install Development tools
在從源代碼構建 Git 之前,需要使用以下 dnf 命令安裝開發工具。
$ sudo dnf groupinstall 'Development Tools' -y
接下來,使用下面的命令安裝其他必需的依賴項
$ sudo dnf install wget curl-devel perl-ExtUtils-MakeMaker gettext openssl-devel zlib-devel curl-devel expat-devel -y
2) 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
4) Compile and Install Git
使用以下命令編譯 Git 源代碼
$ make configure
$ ./configure --prefix=/usr
$ sudo make all
$ sudo make install
5) Verify the Installation
安裝完成後,驗證安裝的 Git 版本
$ git --version
配置 Git
在安裝 Git 之後,設置您的用户名和電子郵件是必要的,此信息將與您的提交相關聯。
1) Set Your Username
$ git config --global user.name "Pradeep Kumar"
2) Set Your Email Address
$ git config --global user.email "info@linuxtechi.com"
3) Verify the Configuration
$ git config --list