How to install Git on Ubuntu 26.04

How to install Git on Ubuntu 26.04

In this blog post, we will show you how to install Git on Ubuntu 26.04 OS. Git is an open-source, freely distributed version control system designed for easy tracking of code changes during the development process. It works perfectly when there are a lot of developers working on the same project on different parts of its functionality. Using Git gives us an option for managing project history, and it acts like a time machine when we need some file from the “history,” allowing us to revert it very easily. Git has a distributed architecture, supports branching and merging, provides integrity and security, and enables great collaboration.

Installing Git is a straightforward process that may take from half a minute to a couple of minutes, depending on the method we use. Let’s get started!

Prerequisites

Update the System

Before we install Git, we will update the system packages to their latest versions. Execute the following command:

apt update -y && apt upgrade -y

Install Git from the Repository

Git is included by default in the latest Ubuntu 26.04 repository. Installing Git from a repository is the fastest and easiest way. To install Git, execute the following command:

apt install git -y

Once installed, check the Git version with the command below:

git -v

You should get the following output:

root@test.vps:~# git -v
git version 2.51.0

The Git version in the official Ubuntu 26.04 repo is 2.51.0, but it is not the latest version. The latest Git version is 2.52.0, which we will install from source in the next heading.

Install Git from Source

The primary reasons we install packages from source on Linux are access to the latest software versions, customization and configuration options, performance optimizations during code compilation, and security considerations. In our case, now we need the latest version of Git, and first we need to remove (purge) the currently installed Git version if there is any:

apt purge git* -y

Before we download the source code, we need to install some prerequisites:

apt install build-essential libssl-dev libcurl4-gnutls-dev libexpat1-dev gettext cmake gcc unzip curl autoconf -y

Once installed, we need to download the latest Git version:

cd /opt && curl -L https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.52.0.tar.gz -o git.tar.gz

Unzip the compressed git file:

tar -zxf git.tar.gz

Once exctracted go into the extracted git directory:

cd git-2.52.0/

Next is to compile Git. Execute the following commands one-by-one:

make configure

./configure --prefix=/usr/local

make all

Once the code is compiled, we can install it with the command below:

make install

After the installation is complete, to ensure your shell uses the newly installed Git version, make a symbolic link with the following command:

ln -s /usr/local/bin/git /usr/bin/git

After creating the link, you can check the version:

git -v

You should get the following output:

root@test.vps:~# git -v
git version 2.52.0

Now the system is using Git version 2.52.0

Git Commands

This is a list of the most used Git commands:

1. git init – Initialize a new Git repository in the current directory.

git init .

2. git clone – Copy a remote repository locally.

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

3. git status – Show the state of changes in your working directory and staging area.

git status

4. git add – Stage file changes for the next commit.

 git add file.txt

5. git commit – Record staged changes with a message.

git commit -m "Describe what you changed"

6. git push – Send your committed changes to a remote repository.

git push origin master

7. git pull – Fetch updates from a remote repository and merge them locally.

git pull origin master

8. git branch – List, create, or delete branches.

git branch development

9. git checkout – Switch branches (or restore files).

git checkout development

10. git merge – Merge another branch into your current branch.

git merge development

11. git log – View commit history.

git log    

12. git diff – Show changes between commits, branches, or working directory and staging area.

git diff

13. git remote – Manage remote connections.

git remote add origin https://github.com/user/repo.git

14. git fetch – Retrieve updates from remote without merging.

git fetch

15. git stash – Temporarily save changes without committing.

git stash

These commands cover the core of typical Git workflows — from starting a repo and making commits to collaborating via remote services like GitHub or GitLab.

Wrap Up

That’s it. You successfully installed Git on Ubuntu 26.04 OS. Of course, you don’t have to make this installation yourself. If you have difficulties and are not familiar with Linux. You can always contact our technical support. You only need to sign up for one of the RoseHosting Linux hosting plans and submit a support ticket. We are available 24/7 and will address your request immediately.

If you liked this post on how to install Git on Ubuntu 26.04, please share it with your friends or leave a comment down below.

Leave a Comment