如何在Ubuntu 20.04上从源代码安装Git [快速入门]

介绍 (Introduction)

Version control systems help you collaborate on software development projects. Git is one of the most popular version control systems currently available.

版本控制系统可帮助您在软件开发项目上进行协作。 Git是当前最流行的版本控制系统之一。

This tutorial will walk you through installing and configuring Git from source on an Ubuntu 20.04 server. For a more detailed version of this tutorial, with more thorough explanations of each step, please refer to How To Install Git on Ubuntu 20.04.

本教程将引导您从Ubuntu 20.04服务器上的源代码安装和配置Git。 有关本教程的更详细版本,以及每个步骤的更详尽说明,请参阅如何在Ubuntu 20.04上安装Git

步骤1 —确认Git预安装 (Step 1 — Confirm Git Preinstallation)

Verify whether you have a version of Git currently installed on the server:

验证服务器上当前是否安装了Git版本:

  • git --version

    git --version

If Git is installed, you’ll receive output similar to the following:

如果安装了Git,您将收到类似于以下内容的输出:


   
   
Output
git version 2.25.1

Whether or not you have Git installed already, it is worth checking to make sure that you install a more recent version during this process.

无论您是否已经安装了Git,都值得检查以确保在此过程中安装了最新版本。

步骤2 —更新和安装依赖项 (Step 2 — Update and Install Dependencies)

You’ll next need to install the software that Git depends on. This is all available in the default Ubuntu repositories, so we can update our local package index and then install the relevant packages.

接下来,您需要安装Git依赖的软件。 这在默认的Ubuntu存储库中都可用,因此我们可以更新本地软件包索引,然后安装相关软件包。

  • sudo apt update

    sudo apt更新
  • sudo apt install libz-dev libssl-dev libcurl4-gnutls-dev libexpat1-dev gettext cmake gcc

    sudo apt安装libz-dev libssl-dev libcurl4-gnutls-dev libexpat1-dev gettext cmake gcc

Press y to confirm if prompted. Necessary dependencies should now be installed.

y确认是否出现提示。 现在应安装必需的依赖项。

第3步-安装Tarball (Step 3 — Install Tarball)

Create a temporary directory to download our Git tarball and move into it.

创建一个临时目录以下载我们的Git tarball并移入该目录。

  • mkdir tmp

    mkdir tmp
  • cd /tmp

    cd / tmp

From the Git project website, we can navigate to the 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.2, 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/上的压缩包列表,然后下载所需的版本。 在撰写本文时,最新版本是2.26.2,因此我们将下载该版本以进行演示。 我们将使用curl并将下载的文件输出到git.tar.gz

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

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

步骤4 —解压缩压缩文件并安装软件包 (Step 4 — Unpack Compressed File and Install the Package)

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 /本地安装

Now, replace the shell process so that the version of Git we just installed will be used:

现在,替换外壳程序,以便使用我们刚安装的Git版本:

  • exec bash

    执行重击

步骤5 —验证新版本的Git (Step 5 — Verify New Version of Git)

You can be sure that your install was successful by checking the version.

您可以通过检查版本来确保安装成功。

  • git --version

    git --version

   
   
Output
git version 2.26.2

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

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

步骤6 —设置Git (Step 6 — Set Up Git)

Now that you have Git installed and to prevent warnings, you should configure it with your information.

现在,您已经安装了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 ”

If you need to edit this file, you can use a text editor such as nano:

如果需要编辑此文件,则可以使用文本编辑器,例如nano:

  • nano ~/.gitconfig

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

翻译自: https://www.digitalocean.com/community/tutorials/how-to-install-git-from-source-on-ubuntu-20-04-quickstart

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值