Xuemeng Technology
This article was first published in:
https://www.itcoder.tech/posts/how-to-install-git-on-ubuntu-20-04/
Git is the most popular distributed version control system in the world, and it is adopted by many open source and commercial projects. It allows you to collaborate with your development colleagues, track your code changes, restore the previous staging area, create branches, and more.
Git was originally developed by Linus Torvalds, the creator of the Linux kernel.
This guide explains how to install and configure Git on Ubuntu 20.04.
The Git package is included in Ubuntu's default software source repository and can be installed using the apt package management tool. This is the most convenient and easiest way to install Git on Ubuntu.
If you want to compile and install the latest Git version from the Git source code, please follow the section "Install Git from Source Code".
The installation is very straightforward, just run the following command as a sudo user:
sudo apt update
sudo apt install git
Run the following command to print the Git version and verify the installation process:
git --version
As of this writing, the current version of Git available under Ubuntu 20.04 is 2.25.1
:
git version 2.25.1
that's it. You have successfully installed Git on your Ubuntu, and you can start using it.
The biggest advantage of installing Git from source is that you can compile the latest Git release and customize the compilation options. In any case, you will not be able to maintain your Git installation process through the apt
software manager.
Start installing the dependent packages to build Git on your Ubuntu system:
sudo apt update
sudo apt install dh-autoreconf libcurl4-gnutls-dev libexpat1-dev make gettext libz-dev libssl-dev libghc-zlib-dev
Next, open your browser, browse Git project mirror on Github and copy the latest release link URL ending in .tar.gz
. At the time of writing this article, the latest stable version of Git is 2.26.2
:
We will download and unzip the Git source code to the /usr/src
directory. This directory is usually used to store source code.
wget -c https://github.com/git/git/archive/v2.26.2.tar.gz -O -| sudo tar -xz -C /usr/src
When the download is complete, switch to the source directory and run the following commands to compile and install Git:
cd /usr/src/git-*
sudo make prefix=/usr/local all
sudo make prefix=/usr/local install
The compilation process will take several minutes. Once completed, to verify the installation process, run:
git --version
The output is as follows:
git version 2.26.2
Later, when you want to upgrade to a new version of Git, use the same process.
The first thing after you install Git is to configure your Git username and email address. Git associates your identity every time you commit code.
To set the global commit name and email address, run the following command:
git config --global username "Your Name"
git config --global user.email "[email protected]"
You can verify the configuration, enter:
git config --list
The output should look like this:
user.name=Your Name
[email protected]
The configuration file is stored in the ~/.gitconfig
file:
[ user]
name = Your Name
email = [email protected]
If you make further changes to the Git configuration, you can use the git config
command (recommended method) or manually edit the ~/.gitconfig
file.
Installing Git on Ubuntu is simply a matter of running an apt
command. If you want to use the latest Git release, you can compile it from source.
To learn more about Git, please visit the Pro Git book website.
Recommended Posts