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.

1. Install Git with Apt

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.

Second, install Git from source code

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 with .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.

Three, configure Git

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.

Four, summary##

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

How to install Git on Ubuntu 20.04
How to install Git on Ubuntu 20.04
How to install Git on Ubuntu 18.04 [Quick Start]
How to install Ruby on Ubuntu 20.04
How to install Memcached on Ubuntu 20.04
How to install Java on Ubuntu 20.04
How to install MySQL on Ubuntu 20.04
How to install VirtualBox on Ubuntu 20.04
How to install Elasticsearch on Ubuntu 20.04
How to install Protobuf 3 on Ubuntu
How to install Apache on Ubuntu 20.04
How to install Node.js on Ubuntu 16.04
How to install MySQL on Ubuntu 20.04
How to install Git on CentOS 8
How to install Vagrant on Ubuntu 20.04
How to install Bacula-Web on Ubuntu 14.04
How to install Anaconda3 on Ubuntu 18.04
How to install Memcached on Ubuntu 18.04
How to install Jenkins on Ubuntu 16.04
How to install MemSQL on Ubuntu 14.04
How to install Go on Ubuntu 20.04
How to install MongoDB on Ubuntu 16.04
How to install Mailpile on Ubuntu 14.04
How to install PrestaShop on Ubuntu 16.04
How to install Skype on Ubuntu 20.04
How to install Jenkins on Ubuntu 20.04
How to install Python 3.8 on Ubuntu 18.04
How to install KVM on Ubuntu 18.04
How to install KVM on Ubuntu 20.04
How to install opencv3.0.0 on ubuntu14.04
How to install Anaconda on Ubuntu 20.04
How to install Prometheus on Ubuntu 16.04
How to install Jenkins on Ubuntu 18.04
How to install Apache on Ubuntu 20.04
How to install R on Ubuntu 20.04
How to install Moodle on Ubuntu 16.04
How to install Solr 5.2.1 on Ubuntu 14.04
How to install Teamviewer on Ubuntu 16.04
How to install MariaDB on Ubuntu 20.04
How to install Nginx on Ubuntu 20.04
How to install Mono on Ubuntu 20.04
How to install Go on Ubuntu 20.04
How to install Zoom on Ubuntu 20.04
How to install Nginx on Ubuntu 16.04
How to install OpenCV on Ubuntu 20.04
How to install Spotify on Ubuntu 20.04
How to install Postman on Ubuntu 18.04
How to install Go 1.6 on Ubuntu 16.04
How to install Go on Ubuntu 18.04
How to install MySQL on Ubuntu 14.04
How to install PostgreSQL on Ubuntu 20.04
How to install VLC on Ubuntu 18.04
How to install TeamViewer on Ubuntu 20.04
How to install Webmin on Ubuntu 20.04
How to install Docker Compose on Ubuntu 18.04
How to install Ubuntu on Raspberry Pi
How to install Bacula Server on Ubuntu 14.04
How to install MySQL on Ubuntu 18.04 (linux)
How to install Ubuntu 19.10 on Raspberry Pi 4
How to install Apache Kafka on Ubuntu 18.04
How to install Apache Maven on Ubuntu 20.04