1. Check the Git version
First of all, we connect to the Raspberry Pi through the SSH client. By viewing the Git version information in the Raspberry Pi, we can only see the highest version displayed as 2.30.2
, and Git cannot be updated to the latest version through apt installation.
git --version
sudo apt upgrade git
Then we can only install Git by building from source code. Building from source code is a simple process that involves downloading, compiling and installing the source code on the system.
Here are the steps to build and install Git from source:
2. Install the required dependencies:
Git requires several dependencies to be installed on your system before it can be built from source. On Ubuntu or Debian based systems, you can install these dependencies by running the following command in terminal:
sudo apt-get install libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev
On other systems, you may need to use a different package manager or install dependencies manually.
3. Download the Git source code:
We can download the latest version of the Git source package from the Git official website , or we can clone the Git repository from GitHub by running the following command through the terminal:
git clone https://github.com/git/git.git
4. Compile the source code:
Enter the directory where you downloaded or cloned the Git source code to compile and install:
cd git
make prefix=/usr/local all
sudo make prefix=/usr/local install
You need to wait patiently for a while during the compilation and installation process, and it will automatically complete the installation in a few simple steps.
5. Check whether Git has been successfully upgraded:
Enter the following command in the terminal to check that Git is installed and running properly.
git --version
Check the displayed Git version number to see if it has changed to the version just compiled and installed. If the displayed version is still old, you can restart the device and check it again.
sudo reboot
Check the Git version again, it has been successfully upgraded from 2.30.2 to 2.40.1
pi@Rpi4B2G:~ $ git --version
git version 2.40.1.515.g5597cfdf47
That's it! You have successfully built and installed Git from source on your system.
The construction and installation method in this article is also applicable to any Ubuntu / Debian distribution