Git is a popular version control system that enables developers to track changes in their codebase and quickly interact with others. It is widely used in the software development business and has evolved into an essential tool for many programmers.
In this article will walk you through the Installation of Git on Linux.
Table of Contents
Prerequisites
- Access to a user account that has sudo or root rights.
- A computer that is running Ubuntu 20.04 or 22.04.
- Access to a command line/terminal window (Ctrl+Alt+T).
Install Git using APT
This is the easiest way to install Git on your system because Git package is included in the official Ubuntu repositories.If you wish to install a specific version or latest stable version, you need to Install Git from source.
Step 1: Install System Updates
First, it’s a good idea to keep the system packages up to date. Start a terminal and enter the following command:
sudo apt update
cloudbooklet@ubuntu:-$ sudo apt update
Hit:1 http://security.ubuntu.com/ubuntu jammy-security InRelease
Hit:2 http://us.archive.ubuntu.com/ubuntu jammy InRelease
Hit:3 http://us.archive.ubuntu.com/ubuntu jammy-updates InRelease
Hit:4 http://us.archive.ubuntu.com/ubuntu jammy-backports InRelease
Yeading package lists... 99%
This command will refresh the package listings in preparation for upgrades and new package installations.
Then, if there are any pending upgrades, upgrade the system:
sudo apt upgrade
cloudbooklet@ubuntu:-$ sudo apt upgrade
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
The following packages were automatically installed and are no lon
ger required:
libflashromi libftdi1-2 1ibllvmi3 virtualbox-guest-utils
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
libatomic1 libllvmi5 linux-headers-5.19.0-45-generic
linux-hwe-5.19-headers-5.19.0-45 linux-image-5.19.0-45-generic
linux-modules-5.19.0-45-generic
linux-modules-extra-5.19.0-45-generic systemd-hwe-hwdb
The following packages will be upgraded:
accountsservice alsa-ucm-conf apparmor apport apport-gtk apt
apt-utils avahi-autoipd avahi-daemon avahi-utils base-files
bind9-dnsutils bind9-host bindo-libs britty ca-certificates
cpp-11 cups cups-browsed cups-bsd cups-client cups-common
cups-core-drivers cups-daemon cups-filters
cups-filters-core-drivers cups-ipp-utils cups-ppdc
Step 2: Install Git
You can use the apt package manager, which is Ubuntu’s default package management, to install Git on Linux. To install Git, execute the following command:
sudo apt install git
cloudbooklet@ubuntu:-$ sudo apt install git
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no
nger required:
Llibflashrom1 libftdi1-2 1ibllvm13 virtualbox-guest-utils
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
git-man liberror-perl
Suggested packages:
git-daemon-run | git-daemon-sysvinit git-doc git-email
git-gui gitk gitweb git-cvs git-mediawiki git-svn
The following NEW packages will be installed:
git git-man liberror-perl
© upgraded, 3 newly installed, © to remove and 1 not upgraded.
Need to get 4,147 kB of archives.
After this operation, 21.6 MB of additional disk space will be
used.
Do you want to continue? [y/n]
During the installation, you may be asked to confirm the installation by typing ‘y’ and pressing Enter. Please do so in order for the installation to proceed. The system will then download and install the Git package and any dependencies.
Step 3: Verify the Installation
Once the installation is complete, you can check the version to ensure that Git was appropriately installed. Execute this command:
git --version
If Git was successfully installed, the version number will be displayed in the output terminal.
cloudbooklet@ubuntu:-$ git --version
git version 2.34.1
cloudbooklet@ubuntu:-$
Install Git from Source
If you wish to install a specific version of Git or any latest stable version, you need to compile Git from source. Make sure you install the dependencies required to install from source.
sudo apt update
sudo apt install dh-autoreconf libcurl4-gnutls-dev libexpat1-dev make gettext libz-dev libssl-dev libghc-zlib-dev
Now choose the version you need to install and copy the tar.gz
link from the official git releases page.

Now you can download and extract the version you wish to the /usr/share
directory.
sudo wget -c https://github.com/git/git/archive/refs/tags/v2.41.0.tar.gz -O - | sudo tar -xz -C /usr/src
Once the download is completed you can move inside the directory and execute the following commands to compile and install Git.
cloudbooklet@ubuntu:-$ sudo wget -c https://github.com/git/git/archive/refs/ta
9s/v2.41.0.tar.gz -0 - | sudo tar -xz -C jusr/src
--2623-66-27 04 3-- https: //github.con/git/git/archive/refs/tags/v2
.41.0.tar.gz
Resolving github.com (github.com)... 26.207.73.82
Connecting to github.com (github.com)|26.207.73.82|:443... connected.
HTTP request sent, awaiting response... 362 Found
Location: https://codeload.github.com/git/git/tar.gz/refs/tags/v2.41.0 [
following]
--2623-66-27 04:09:13-- https://codeload.github.con/git/git/tar.gz/refs
/tags/v2.41.0
Resolving codeload.github.com (codeload.github.com)... 20.207.73.88
Connecting to codeload.github.con (codeload.github.com)|26.267.73.88] :44
3... connected.
HTTP request sent, awaiting response... 260 OK
Length: 10884275 (16M) [application/x-gzip]
saving to: ‘STDOUT’
- 8%[> ] 912.38K 1.89MB/s
Here are the instructions for compiling and installing Git on Linux:
cd /usr/src/git-*
sudo make prefix=/usr/local all
sudo make prefix=/usr/local install
cloudbooklet@ubuntu:~$ cd /usr/src/git-*
sudo make prefix=/usr/Tocal all
Sudo make prefix=/usr/Tocal install
GIT_VERSION = 2.41.6
* new build flags
CC oss-fuzz/fuzz-conmit-graph.o
CC oss-fuzz/fuzz-pack-headers.o
CC oss-fuzz/fuzz-pack-idx.o
CC daemon.o
* new link flags
CC common-main.o
cc abspath.o
CC add-interactive.o
CC add-patch.o
CC advice.o
CC alias.o
CC alloc.o
cc apply.o
CC archive-tar.o
cc archive-zip.o
This will take some time for the installation process to completed. Once the installation is complete, you can check the Git installation on your Ubuntu system by running the following command:
git --version
You will get a sample output similar to the one below.
cloudbooklet@ubuntu:-$ git --version
git version 2.34.1
cloudbooklet@ubuntu:-$
Now you have compiled and installed Git from source.
Configure the Git User Information
Before you begin using Git, you should configure your user information. This data will be linked to any commits you make in a Git repository. Replace the placeholders with your own name and email address and run the following commands:
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
You may check the configuration settings by running the command:
git config --list
A list of setup items, including your name and email address, will be displayed.
Output sample:
user.name=Your Name
[email protected]
...
If you prefer to manually edit the Git configuration file, you can do so with any text editor you like, such as nano:
nano ~/.gitconfig
Now your changes will be saved inside the ~/.gitconfig
folder.
Also read: You might also find useful our guide on How to Modify the Hostname in Linux
Conclusion
To summarize, installing Git on Linux is a simple process. By following the provided steps, you can easily set up Git, update your system, and configure your user information. You are now ready to use Git’s sophisticated version control capabilities for your software development projects after successfully installing it.
Thanks for your time. If you face any problem or any feedback, please leave a comment below.