The most common situation is when you want to install the latest version of git, but your Operating System's repositories are not updated. For example, in my case I have a laptop running Ubuntu 20.04, and when I executed the command sudo apt install git
the installed version was 2.25.1; instead of 2.32.0 which is the current version at git-scm.com.
How can I get the latest version?
Well, we can install it by following one of these methods: Using APT Reprositories, Building and Installing or Using binary files.
A. Building and Installing (recommended for developers)
A-1. Uninstall the default version provided by Ubuntu's package manager and configuration by using:
sudo apt remove --purge --auto-remove -y git
or:
sudo apt purge --auto-remove -y git
A-2. Go to the official CMake webpage, then download and extract the latest version. Update the version
and build
variables in the following command to get the desired version:
version=2.32
build=0
mkdir ~/temp
cd ~/temp
wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-$version.$build.tar.gz
tar -xzvf git-$version.$build.tar.gz
cd git-$version.$build/
A-3. Install the extracted source by running:
make -j$(nproc) prefix=/usr/local all
sudo make prefix=/usr/local install
A-4. Test your new git
version.
git --version
Results of git --version
:
git version 2.25.X
B. Using PPA Repositories (recommended for normal users)
There is a PPA available from Ubuntu Git Maintainers team that we can use to easily install the latest stable Git version. So we can install it easily following these steps:
B-1. Uninstall the default version provided by Ubuntu's package manager as in A-1.
B-2. Add PPA repository to your sources list.
sudo add-apt-repository ppa:git-core/ppa
B-3. Finally we can update and install the git
package.
sudo apt update
sudo apt install git
B-4. Test your new git
version as in A-4.
Note
In 2.32.X the X represents the last part of the version that we defined as build. The build may change if git is updated. According to the official web page the Latest Release is 2.32.0. If you want the Previous Release 2.31.1 just replace the version and build parameters like this:
version=2.31
build=1
mkdir ~/temp
cd ~/temp
wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-git-$version.$build.tar.gz
tar -xzvf git-$version.$build.tar.gz
cd git-$version.$build/