centos上安装git_如何在CentOS 8上安装Git

centos上安装git

介绍 (Introduction)

Version control systems are an indispensable part of modern software development. Versioning allows you to keep track of your software at the source level. You can track changes, revert to previous stages, and branch to create alternate versions of files and directories.

版本控制系统是现代软件开发中必不可少的部分。 版本控制使您可以在源代码级别跟踪软件。 您可以跟踪更改,还原到上一个阶段以及分支以创建文件和目录的备用版本。

One of the most popular version control systems currently available is Git. Many projects’ files are maintained in a Git repository, and sites like GitHub, GitLab, and Bitbucket help to facilitate software development project sharing and collaboration.

当前可用的最流行的版本控制系统之一是Git。 许多项目的文件都保存在Git存储库中,而GitHub,GitLab和Bitbucket等站点则有助于促进软件开发项目的共享和协作。

In this guide, we will go through how to install and configure Git on a CentOS 8 server. We will cover how to install the software two different ways: via the built-in package manager and via source. Each of these approaches has their own benefits depending on your specific needs.

在本指南中,我们将介绍如何在CentOS 8服务器上安装和配置Git。 我们将介绍如何以两种不同的方式安装软件:通过内置的软件包管理器和通过源。 这些方法中的每一种都有自己的优势,具体取决于您的特定需求。

先决条件 (Prerequisites)

You will need a CentOS 8 server with a non-root superuser account.

您将需要具有非超级用户超级帐户的CentOS 8服务器。

To set this up, you can follow our Initial Server Setup Guide for CentOS 8.

要进行设置,您可以遵循我们的《 CentOS 8初始服务器设置指南》

With your server and user set up, you are ready to begin.

设置好服务器和用户后,就可以开始了。

使用默认软件包安装Git (Installing Git with Default Packages)

Our first option to install Git is via CentOS’s default packages.

我们安装Git的第一个选择是通过CentOS的默认软件包。

This option is best for those who want to get up and running quickly with Git, those who prefer a widely-used stable version, or those who are not looking for the newest available options. If you are looking for the most recently release, you should jump to the section on installing from source.

对于那些希望通过Git快速启动并运行的用户,更喜欢使用广泛使用的稳定版本的用户,或者不希望找到最新可用选项的用户而言,此选项是最佳选择。 如果您正在寻找最新版本,则应跳至有关从源安装的部分。

We will be using the open-source package manager tool DNF, which stands for Dandified YUM the next-generation version of the Yellowdog Updater, Modified (that is, yum). DNF is a package manager that is now the default package manager for Red Hat based Linux systems like CentOS. It will let you install, update, and remove software packages on your server.

我们将使用开源程序包管理器工具DNF,它代表Dandified YUM,即Yellowdog Updater Modified(即yum)的下一代版本。 DNF是一个程序包管理器,现在是基于Red Hat的Linux系统(如CentOS)的默认程序包管理器。 它使您可以在服务器上安装,更新和删除软件包。

First, use the DNF package management tools to update your local package index.

首先,使用DNF软件包管理工具来更新本地软件包索引。

  • sudo dnf update -y

    须藤dnf更新-y

The -y flag is used to alert the system that we are aware that we are making changes, preventing the terminal from prompting us to confirm.

-y标志用于警告系统我们知道我们正在进行更改,从而防止终端提示我们进行确认。

With the update complete, you can install Git:

更新完成后,您可以安装Git:

  • sudo dnf install git -y

    须藤dnf安装git -y

You can confirm that you have installed Git correctly by running the following command:

您可以通过运行以下命令来确认已正确安装了Git:

  • git --version

    git --version

   
   
Output
git version 2.18.2

With Git successfully installed, you can now move on to the Setting Up Git section of this tutorial to complete your setup.

成功安装Git后,您现在可以转到本教程的“ 设置Git”部分以完成设置。

从源代码安装Git (Installing Git from Source)

A more flexible method of installing Git is to compile the software from source. This takes longer and will not be maintained through your package manager, but it will allow you to download the latest release and will give you some control over the options you include if you wish to customize.

安装Git的一种更灵活的方法是从源代码编译软件。 这将花费更长的时间,并且不会通过软件包管理器进行维护,但是它将允许您下载最新版本,并且如果您希望自定义的话,还可以控制您包括的选项。

Before you begin, you need to install the software that Git depends on. This is all available in the default repositories, so we can update our local package index and then install the packages.

在开始之前,您需要安装Git依赖的软件。 这些在默认存储库中都可用,因此我们可以更新本地软件包索引,然后安装软件包。

  • sudo dnf update -y

    须藤dnf更新-y
  • sudo dnf install gettext-devel openssl-devel perl-CPAN perl-devel zlib-devel gcc autoconf -y

    须藤dnf安装gettext-devel openssl-devel perl-CPAN perl-devel zlib-devel gcc autoconf -y

After you have installed the necessary dependencies, create a temporary directory and move into it. This is where we will download our Git tarball.

安装必要的依赖项后,创建一个临时目录并移入该目录。 这是我们将下载Git tarball的地方。

  • mkdir tmp

    mkdir tmp
  • cd /tmp

    cd / tmp

From the Git project website, we can navigate to the Red Hat Linux distribution tarball list available at https://mirrors.edge.kernel.org/pub/software/scm/git/ and download the version you would like. At the time of writing, the most recent version is 2.26.0, so we will download that for demonstration purposes. We’ll use curl and output the file we download to git.tar.gz.

Git项目网站 ,我们可以导航到https://mirrors.edge.kernel.org/pub/software/scm/git/上提供的Red Hat Linux发行包列表,并下载所需的版本。 在撰写本文时,最新版本是2.26.0,因此我们将下载该版本以进行演示。 我们将使用curl并将下载的文件输出到git.tar.gz

  • curl -o git.tar.gz https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.26.0.tar.gz

    curl -o git.tar.gz https://mirrors.edge.kernel.org/pub/software/scm/git/git- 2.26.0 .tar.gz

Unpack the compressed tarball file:

解压缩压缩的tarball文件:

  • tar -zxf git.tar.gz

    tar -zxf git.tar.gz

Next, move into the new Git directory:

接下来,进入新的Git目录:

  • cd git-*

    cd git- *

Now, you can make the package and install it by typing these two commands:

现在,您可以通过键入以下两个命令来制作软件包并进行安装:

  • make prefix=/usr/local all

    使prefix = / usr / local全部
  • sudo make prefix=/usr/local install

    sudo make prefix = / usr /本地安装

With this complete, you can be sure that your install was successful by checking the version.

完成此操作后,您可以通过检查版本来确保安装成功。

  • git --version

    git --version

   
   
Output
git version 2.26.0

With Git successfully installed, you can now complete your setup.

成功安装Git后,您现在可以完成设置。

设置Git (Setting Up Git)

Now that you have Git installed, you should configure it so that the generated commit messages will contain your correct information.

既然已经安装了Git,则应该对其进行配置,以便生成的提交消息将包含正确的信息。

This can be achieved by using the git config command. Specifically, we need to provide our name and email address because Git embeds this information into each commit we do. We can go ahead and add this information by typing:

这可以通过使用git config命令来实现。 具体来说,我们需要提供我们的姓名和电子邮件地址,因为Git会将这些信息嵌入到我们所做的每次提交中。 我们可以继续输入以下内容来添加此信息:

  • git config --global user.name "Your Name"

    git config --global user.name“ 您的名字 ”

  • git config --global user.email "youremail@domain.com"

    git config --global user.email“ youremail@domain.com ”

We can display all of the configuration items that have been set by typing:

我们可以通过键入以下内容显示已设置的所有配置项:

  • git config --list

    git config --list

   
   
Output
user.name=Your Name user.email=youremail@domain.com ...

The information you enter is stored in your Git configuration file, which you can optionally edit by hand with a text editor like this:

输入的信息存储在Git配置文件中,您可以选择使用文本编辑器手动编辑该文件,如下所示:

  • vi ~/.gitconfig

    vi〜/ .gitconfig
~/.gitconfig contents
〜/ .gitconfig内容
[user]
  name = Your Name
  email = youremail@domain.com

Press ESC then :q to exit the text editor.

ESC然后按:q退出文本编辑器。

There are many other options that you can set, but these are the two essential ones needed. If you skip this step, you’ll likely see warnings when you commit to Git. This makes more work for you because you will then have to revise the commits you have done with the corrected information.

您可以设置许多其他选项,但这是需要的两个基本选项。 如果跳过此步骤,则在提交到Git时可能会看到警告。 这将为您带来更多的工作,因为您将不得不使用更正的信息来修改您所做的提交。

结论 (Conclusion)

You should now have Git installed and ready to use on your system.

现在,您应该已经安装了Git,可以在系统上使用它了。

To learn more about how to use Git, check out these articles and series:

要了解有关如何使用Git的更多信息,请查看以下文章和系列:

翻译自: https://www.digitalocean.com/community/tutorials/how-to-install-git-on-centos-8

centos上安装git

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值