sammlinux sammlinux
  • Ubuntu
    UbuntuShow More
    How To Install and Use Docker CE on Ubuntu 22.04
    26 Min Read
    How To Install and Secure phpMyAdmin on Ubuntu 22.04
    5 Min Read
    How To Secure SSH with Fail2Ban on Ubuntu 22.04
    8 Min Read
    How To Install Uptime Kuma on Ubuntu 22.04
    17 Min Read
    How To Install Ubuntu Server 22.04 LTS with Screenshots
    14 Min Read
  • Rocky Linux
    Rocky LinuxShow More
    How To Install phpMyAdmin on Rocky Linux 9
    15 Min Read
    How To Secure SSH with Fail2Ban on Rocky Linux 9
    12 Min Read
    How To Install Rocky Linux 9.2 Server with Screenshots
    12 Min Read
    How To Set Up a Firewall Using FirewallD on Rocky Linux 9
    8 Min Read
    How To Install Nginx on Rocky Linux 9: A Comprehensive Guide
    10 Min Read
  • Debian
    DebianShow More
    How To Secure SSH with Fail2Ban on Debian 11
    8 Min Read
    How To Install Debian 11 (Bullseye) Server with Pictures
    12 Min Read
    How To Install and Setup Node.js on Debian 11
    6 Min Read
    How To Install PHP 8.2 on Debian 11
    12 Min Read
    How To Install Nginx on Debian 11: A Comprehensive Guide
    9 Min Read
  • Linux
    LinuxShow More
    Best Practices Linux Server Security for System Administrator
    8 Min Read
    A Simple Guide: How To Manage Groups on Linux
    5 Min Read
    How To Manage Log Files Using Logrotate In Linux
    7 Min Read
    The Easy Ways to Check File Size in Linux
    7 Min Read
    How To Backup Files From Remote Linux VPS Using Rsync Script
    12 Min Read
  • CentOS
    CentOSShow More
    How To Secure SSH with Fail2Ban on CentOS 7
    9 Min Read
    How To Install PHP 8.2 on CentOS 7 / RHEL 7
    18 Min Read
    How To Install Apache Web Server on CentOS 7
    11 Min Read
    How To Set Up a Firewall Using FirewallD on CentOS 7
    5 Min Read
    Initial Setup CentOS 7 Server: Secure and Efficient
    9 Min Read
  • DevOps
    DevOpsShow More
    How To Create AWS CloudFront: A Step-by-Step Guide
    10 Min Read
Reading: How To Install and Config Git on Ubuntu 22.04
Share
Font ResizerAa
Linux for BeginnersLinux for Beginners
  • Ubuntu
  • Rocky Linux
  • Debian
  • Linux
  • CentOS
  • DevOps
Search
  • Ubuntu
  • Rocky Linux
  • Debian
  • Linux
  • CentOS
  • DevOps
Follow US
Copyright © 2014-2023 Ruby Theme Ltd. All Rights Reserved.

How To Install and Config Git on Ubuntu 22.04

Samuel Siahaan
By Samuel Siahaan
Last updated: March 30, 2023
SHARE

Introduction Git

This article provides an in-depth, step-by-step guide on how to install and config Git on Ubuntu 22.04, you to take full advantage of its capabilities and streamline your development workflows “How To Install and Configure Git on Ubuntu 22.04”.

Contents
Introduction GitTable of ContentsPrerequisitesInstalling Git on Ubuntu 22.04Option 1: Install Git with the Default Package ManagerStep 1: System UpdateStep 2: Install Git Using AptOption 2: Install Git from the SourceStep 1: Install Required DependenciesStep 2: Download the Git Source CodeStep 3: Compile and Install GitSetting up Git on Ubuntu 22.04Step 1: Add a user and emailStep 2: Verify ConfigurationStep 3: Git InitializationConclusion

In the realm of modern software development, version control is a foundational practice that ensures efficient collaboration, smooth code management, and a clear history of changes.

Table of Contents

  • Introduction Git
  • Prerequisites
  • Installing Git on Ubuntu 22.04
  • Option 1: Install Git with the Default Package Manager
    • Step 1: System Update
    • Step 2: Install Git Using Apt
  • Option 2: Install Git from the Source
    • Step 1: Install Required Dependencies
    • Step 3: Compile and Install Git
  • Setting up Git on Ubuntu 22.04
    • Step 1: Add a user and email
    • Step 2: Verify Configuration
  • Conclusion

Git, a distributed version control system, has revolutionized the way developers work by enabling seamless tracking of changes and collaborative coding. Version control is at the heart of effective software development. It allows developers to track changes to their codebase, work simultaneously on the same project, and revert to previous states if necessary.

Git’s decentralized architecture takes version control a step further by enabling developers to work offline, merge changes effortlessly, and collaborate seamlessly. These practices not only enhance development efficiency but also contribute to better code quality and project management.

- Advertisement -

Prerequisites

Before we dive into the installation process, there is prerequisite you need to ensure are in place:

  • Ubuntu Server: Make sure you have a clean installation of Ubuntu Server (Initial Setup Ubuntu Server 22.04) ready to go. You can deploy this on a physical machine or a virtual environment like VMware or VirtualBox.

Installing Git on Ubuntu 22.04

With Git, you can go back to a particular time and undo changes. With this, you’d agree that Git is a valuable tool under your belt; let’s get on to see how to install git on Ubuntu 22.04!

In this tutorial you will learn:

  • How to install Git
  • How to set global username
  • How to set global email
  • How to check git version

There are two basic methods to get Git up and running Ubuntu 22.04: using the Ubuntu package manager or downloading the official Git distribution. Let’s look at them briefly:

  • Package Manager: A package manager lets you install software directly from the Ubuntu software repositories. This method guarantees easy maintenance and updates through the package management system.
  • Official Git Distribution: Alternatively, you can choose to download and install the official Git distribution directly from the Git project’s website. This method provides the latest version of Git with all its features and enhancements.

Based on your needs, you can use any of the methods.

- Advertisement -

Option 1: Install Git with the Default Package Manager

Installing Git with a package manager like apt offers you ease of installation; it also allows you easily manage and update Git. The version of Git you get with this method may not be the latest version.

Ubuntu 22.04 should have git installed by default. Run the following command to check if you have git installed:

samm@git:~$ git --version
git version 2.34.1

You can install Git using the following steps with apt :

- Advertisement -

Step 1: System Update

Before installing any packages, run the apt command below to update and refresh your Ubuntu repository.

samm@git:~$ sudo apt update

Step 2: Install Git Using Apt

Next, install git using apt by running the following command:

samm@git:~$ sudo apt install git

Once the installation is complete, you can start running git commands from the terminal.

Option 2: Install Git from the Source

This method How to Install Git in Ubuntu, though not as simple as the first method, will provide you with the latest version of Git.

Step 1: Install Required Dependencies

Install the dependencies using the following code:

samm@git:~$ sudo apt install libz-dev libssl-dev libcurl4-gnutls-dev libexpat1-dev gettext cmake gcc

Output:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Note, selecting 'zlib1g-dev' instead of 'libz-dev'
gcc is already the newest version (4:11.2.0-1ubuntu1).
gcc set to manually installed.
libexpat1-dev is already the newest version (2.4.7-1ubuntu0.2).
libexpat1-dev set to manually installed.
zlib1g-dev is already the newest version (1:1.2.11.dfsg-2ubuntu9.2).
zlib1g-dev set to manually installed.
The following additional packages will be installed:
  cmake-data dh-elpa-helper libjsoncpp25 librhash0
Suggested packages:
  cmake-doc ninja-build cmake-format gettext-doc autopoint libasprintf-dev libgettextpo-dev libcurl4-doc libgnutls28-dev libidn11-dev libkrb5-dev libldap2-dev librtmp-dev libssh2-1-dev libssl-doc
The following NEW packages will be installed:
  cmake cmake-data dh-elpa-helper gettext libcurl4-gnutls-dev libjsoncpp25 librhash0 libssl-dev
0 upgraded, 8 newly installed, 0 to remove and 66 not upgraded.
Need to get 10.8 MB of archives.
After this operation, 48.6 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y

At some point, you’ll be asked if you would like to continue, type “Y” to indicate yes and press enter.

Step 2: Download the Git Source Code

Once the packages have been installed, you can go on to download Git. You can get the download link for the latest version from the download page.

To download the latest version of Git as at the time of this writing, run the following code:

samm@git:~$ wget https://www.kernel.org/pub/software/scm/git/git-2.41.0.tar.gz -O git.tar.gz

Output :

--2023-08-06 05:25:36--  https://www.kernel.org/pub/software/scm/git/git-2.41.0.tar.gz
Resolving www.kernel.org (www.kernel.org)... 145.40.73.55, 2604:1380:40e1:4800::1
Connecting to www.kernel.org (www.kernel.org)|145.40.73.55|:443... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.41.0.tar.gz [following]
--2023-08-06 05:25:36--  https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.41.0.tar.gz
Resolving mirrors.edge.kernel.org (mirrors.edge.kernel.org)... 147.75.48.161, 2604:1380:40f1:3f00::1
Connecting to mirrors.edge.kernel.org (mirrors.edge.kernel.org)|147.75.48.161|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 10791798 (10M) [application/x-gzip]
Saving to: ‘git.tar.gz’

git.tar.gz                                           100%[=====================================================================================================================>]  10.29M   293KB/s    in 35s     

2023-08-06 05:26:12 (299 KB/s) - ‘git.tar.gz’ saved [10791798/10791798]

This will download the git source code archive for version 2.41.0 and save it as git.tar.gz in the current directory.

After Git has been downloaded, extract the contents of the file using:

samm@git:~$ tar -zxf git.tar.gz

Step 3: Compile and Install Git

Next, change from the current directory to the extracted git source code directory by running the following in the terminal:

samm@git:~$ cd git-2.41.0/

Once in the extracted git source code directory, you can proceed with the installation of Git. Run the following commands to compile the git source code and install git and also restart the bash shell to save the changes and ensure that the changes are reflected in the current shell session.

Setting up Git on Ubuntu 22.04

Once Git is installed, it is recommended that you make some configurations. In particular, the identification associated with your commits. Rather than having to make this configuration for each repository, it’s possible to make a global configuration using a .gitconfig file located in the root folder of the home user.

Install and Configure Git on Ubuntu
Platforms Repositories GitLab

Step 1: Add a user and email

You can add a global username and email address for Git on your system by running the following:

This file can be made manually or by using the config option with the git command:

git config --global user.name "Firstname Lastname" git config --global user.email "[email protected]"

samm@git:~$ git config --global user.name "tech_sammlinux"
samm@git:~$ git config --global user.email "[email protected]"

Adding these settings will establish consistent authorship across your Git repositories. It helps identify who made specific changes and enables proper collaboration and communication within a team or open-source community.

Step 2: Verify Configuration

Display your .gitconfig file in your home directory:

samm@git:~$ cat .gitconfig

Output :

[user]
	email = [email protected]
	name = tech_sammlinux

Step 3: Git Initialization

You can initialize an existing project folder or make a new directory to initialize Git inside it. create a new directory with mkdir command.

samm@git:~$ mkdir TUTORIAL

Get inside that folder by issuing the following command:

samm@git:~$ cd TUTORIAL/
samm@git:~/TUTORIAL$

The following command will initialize the Git repository in the “TUTORIAL” directory:

samm@git:~/TUTORIAL$ git init

Output :

hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint: 
hint: 	git config --global init.defaultBranch <name>
hint: 
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint: 
hint: 	git branch -m <name>
Initialized empty Git repository in /home/samm/TUTORIAL/.git/

The output shows that the Git repository has been initialized in the “TUTORIAL” directory.

Let’s check the status of Git inside the “TUTORIAL” directory.

samm@git:~/TUTORIAL$ git status

Output :

On branch master

No commits yet

nothing to commit (create/copy files and use "git add" to track)

The command shows that the Git is working inside the “TUTORIAL” and there are no commits encountered yet.

After doing so, you can observe the changes in the Git configuration list as follows:

samm@git:~$ git config --list

Output :

/home/samm/TUTORIAL
[email protected]
user.name=samuelsiahaan

Conclusion

You’ve successfully installed and configured Git on your Ubuntu 22.04 system. Git is now ready for use, allowing you to manage and track changes in your projects effectively. Whether you’re a developer, a student, or someone interested in version control, Git is an essential tool that can simplify and enhance your workflow. Start using Git today to keep track of your project’s history and collaborate seamlessly with others. Happy coding!

Also Read Our Other Guides :

  • How To Install Jenkins on Ubuntu 22.04
  • How To Use Git Version Control on Linux: For Beginner
  • How To Install VirtualBox 7.0 on Ubuntu 22.04
  • How To Install Vagrant on Ubuntu 22.04
  • How To Install and Configure Ansible on Rocky Linux 9
  • How To Create AWS CloudFront: A Step-by-Step Guide
  • How To Install Python 3.11 from Source on Ubuntu 22.04
  • How To Install Python 3.11 on Rocky Linux 9

Finally, now you have learned How To Install and Config Git on Ubuntu 22.04.

TAGGED:DevOpsGitGithubGitlabRepositoryUbuntuVersion Control

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article How To Create and Use Swap File on Linux System
Next Article How To Install Vagrant on Ubuntu 22.04
Leave a Comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

How To Install and Secure phpMyAdmin on Ubuntu 22.04
Ubuntu
Install and Configure Docker Swarm Mode on Centos 7
CentOS
How To Install and Config Thumbor on Debian 10
Debian
How To Install MariaDB 10.6 on Debian 11 Server
Debian
How To Install MongoDB 6.0 on Debian 10 & 11
Debian

You Might Also Like

Ubuntu

How To Install Node.js on Ubuntu 22.04 With 3 Different Ways

20 Min Read
Ubuntu

Initial Setup Ubuntu Server 22.04: Secure and Efficient

16 Min Read
Ubuntu

How To Install Java Using OpenJDK 17 on Ubuntu 22.04

10 Min Read
Ubuntu

How To Install Nextcloud with Apache and MariaDB on Ubuntu Server 22.04

20 Min Read
Ubuntu

How To Install and Configure NFS Server Client on Ubuntu 22.04

16 Min Read
Ubuntu

How To Install MongoDB 6.0 on Ubuntu Server 22.04

10 Min Read
CentOS

How To Install Docker CE on Centos 7

9 Min Read
Ubuntu

How To Install Apache 2.4 on Ubuntu 22.04

10 Min Read
Show More

Always Stay Up to Date

Subscribe to our newsletter to get our newest articles instantly!

sammlinux sammlinux

Providing beginner-friendly Linux tutorials and open-source guides to simplify your digital infrastructure.

www.sammlinux.com © 2026 | All Rights Reserved

Join Us!
Subscribe to our newsletter and never miss our latest news, podcasts etc.

Subscribe to our newsletter to get our newest articles instantly!

Zero spam, Unsubscribe at any time.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?