How to Install Git on Ubuntu: A Beginners’ Guide To Success 

install git on ubuntu

Table of Contents

Get up to 50% off now

Become a partner with CyberPanel and gain access to an incredible offer of up to 50% off on CyberPanel add-ons. Plus, as a partner, you’ll also benefit from comprehensive marketing support and a whole lot more. Join us on this journey today!

Git is one of the most widely used distributed version control systems that helps developers track changes in source code, collaborate on projects, and manage the source code efficiently. It is an essential development tool for software development, allowing teams to work on the same codebase without issues. 

Ubuntu, being a popular Linux distribution, provides an easy way to install and configure Git.    

Whether you are a beginner or an experienced developer, you could install Git on Ubuntu so that you can seamlessly collaborate within the team. 

In this guide, we will walk you through the easy steps to install Git on Ubuntu with proper configurations and commands. 

Prerequisites for Installing Git on Ubuntu

Before you install Git on Ubuntu, make sure that your system meets the basic requirements: 

  1. A system that runs Ubuntu 20.04, 22.04, or other supported versions. 
  2. Access to a terminal or command line tool. 
  3. Sudo admin privileges to install Git on Ubuntu. 
  4. Updated packages list to ensure that you get the latest version. If you need to update the package list, run the following command: sudo apt update && sudo apt upgrade -y
  5. A stable internet connection. 
  6. If you plan to install Git from source, ensure that you have build-essential, libssl-dev, and curl installed:
    sudo apt install build-essential libssl-dev curl -y

Installing Git on Ubuntu

There are two basic methods to install Git on Ubuntu, one is through the default APT package manager and the other one is by compiling the latest version from the source. 

Tech Delivered to Your Inbox!

Get exclusive access to all things tech-savvy, and be the first to receive 

the latest updates directly in your inbox.

Installing Git Using APT

The easiest and most reliable way to install Git on Ubuntu is by using the APT package manager. 

Step 1: Update the Package List

Before you install Git on Ubuntu, you need to update your package list to ensure that you get the latest version available in the repositories. 

sudo apt update && sudo apt upgrade -y

Step 2: Install Git

Run the following command to install Git:

sudo apt install git -y

Step 3: Verify the Installation

To verify the installation, you can run the following command: 

git –version

This method instals the most stable version of Git that is maintained by Ubuntu. 

Related Article: How To Install Kubernetes on Ubuntu 22.04: A Step-by-Step Guide

Installing the Latest Git Version from Source

If you need to install the latest version of Gill with the newest features and bug fixes, you can compile it directly from the source. 

Enhance Your CyerPanel Experience Today!
Discover a world of enhanced features and show your support for our ongoing development with CyberPanel add-ons. Elevate your experience today!

Step 1: Install Required Dependencies

Install the required packages by: 

sudo apt install build-essential libssl-dev libghc-zlib-dev libcurl4-gnutls-dev -y

Step 2: Download the Latest Git Source Code

Navigate to the /usr/src directory and download the latest Git release from its official website:

cd /usr/src

sudo wget https://github.com/git/git/archive/refs/tags/v2.44.0.tar.gz -O git.tar.gz

Step 3: Extract and Compile Git

Extract and compile the files using: 

sudo tar -xvzf git.tar.gz

cd git-*

sudo make prefix=/usr/local all

sudo make prefix=/usr/local install

Step 4: Verify the Installation

Verify installation by: 

git –version

Verifying the Git Installation

Once you have installed Git on Ubuntu, you need to verify by checking its version.  

git –version

If Git is installed successfully, you will see the Git version. However, if there was an issue with the installation, it will return an error. If this is the case, then you should try re-installing Git. 

Configuring Git on Ubuntu 

After you install Git on Ubuntu, you should configure your username and email address to commit the essential changes.  

Set Up Your Git Identity

git config –global user.name “Your Name”

git config –global user.email “[email protected]

Verify your configuration with:

git config –list

To manually edit the configuration file, run the command: 

git config –global –edit

Basic Git Commands to Get Started

Once Git is installed and configured, you can start using it for version control.

Initialize a New Repository:

git init my_project

cd my_project

Clone an Existing Repository

git clone https://github.com/user/repository.git

Check Repository Status

git status


No tracked files because we didn’t commit any files over Git on the actual server.

Add Files to Staging Area

git add filename  

git add .

Commit Changes

git commit -m “Initial commit”

Pu  Changes to a Remote Repository

git pu  origin main

Pull Latest Changes

git pull origin main 

Upgrading and Uninstalling Git

Upgrade Git on Ubuntu

If you install Git on Ubuntu via APT, upgrade it using the command lines:

sudo apt update && sudo apt upgrade git -y

Alternatively, if you install Git from source, you can download the latest release and recompile it using the same steps as above. 

Uninstall Git on Ubuntu

To remove Git installed via APT:

sudo apt remove –purge git -y

For installations from source, delete Git’s binaries:

sudo rm -rf /usr/local/bin/git

sudo rm -rf /usr/src/git*

Troubleshooting Guide To Install Git on Ubuntu

IssuePossible CauseSolution
command not found: gitGit is not installed or not in the system path.Install Git using sudo apt install git -y, or check the installation path with which git.
Unable to fetch updates from a remote repositoryIncorrect repository URL or no internet connection.Verify the remote URL with git remote -v and check your internet connection.
Permission denied (publickey) error when using SSHSSH keys are not set up correctly.Generate an SSH key using ssh-keygen -t rsa -b 4096 and add it to GitHub/GitLab.
Git version not updating after upgradeOld Git version is still in use.Restart the terminal and run git –version. If the issue persists, remove old versions using sudo apt remove git before reinstalling.
SSL certificate problem: unable to get local issuer certificateSystem’s CA certificates are outdated.Update certificates using sudo apt install –reinstall ca-certificates.
fatal: repository not foundThe repository URL is incorrect or the repository doesn’t exist.Double-check the repository URL and confirm it exists.
fatal: not a git repositoryRunning Git commands in a non-Git directory.Navigate to a Git repository using cd /path/to/repo, or initialize one with git init.
Git is too slow when cloning repositoriesLarge repositories or slow internet connection.Use git clone –depth=1 <repo_url> for a shallow clone, or improve network speed.

Wrapping Up – Install Git on Ubuntu 

It is an easy process to install Git on Ubuntu and does not require too much technical knowledge. This article is an easy guide to installation, configuring, and troubleshooting issues while using Git with Ubuntu. 

Frequently Asked Questions

1. How do I configure Git after installation?

Set up your Git username and email:
git config --global user.name "Your Name" git config --global user.email "[email protected]"

2. How do I uninstall Git from Ubuntu?

To remove Git, run:
sudo apt remove --purge git -y

3. How do I check if Git is installed?

Use this command to verify the installation:
git --version

Marium Fahim
Hi! I am Marium, and I am a full-time content marketer fueled by an iced coffee. I mainly write about tech, and I absolutely love doing opinion-based pieces. Hit me up at [email protected].
Unlock Benefits

Become a Community Member

SIMPLIFY SETUP, MAXIMIZE EFFICIENCY!
Setting up CyberPanel is a breeze. We’ll handle the installation so you can concentrate on your website. Start now for a secure, stable, and blazing-fast performance!