Raspberry Pi

How to Install Git on Raspberry Pi

Git is an open-source, actively maintained distributed version control system that handles minor to major projects efficiently. It is generally utilized for source code management on the software development side and allows the developers to collaborate. Other developers can easily track the source code shared by a developer on the server, so any changes to the source code will also notify other developers.

In this article, you will learn how to install Git on Raspberry Pi through different methods to pick a suitable one for yourself. So, let’s dive into the guidelines.

Install Git on Raspberry Pi

On a Raspberry Pi system, you can install Git from the following two methods:

Method 1: Install Git from Raspberry Pi Repository

The Raspberry Pi official repository includes the Git repository, making it a straightforward task to install it on your Raspberry Pi system through the “apt” command. However, before starting the installation process, you should first update the Raspberry Pi repository from the following command:

$ sudo apt update && sudo apt upgrade -y

After updating the repository list of Raspberry Pi, you can then install Git from the below-given command:

$ sudo apt install git -y

After the installation, you can check the Git version on Raspberry Pi via the following command:

$ git --version

Through the above method, you won’t be able to install the latest version of Git, but the version you get won’t be the older one either.

Method 2: Install Git on Raspberry Pi from GitHub Source

In case you want to install the latest version of Git on your Raspberry Pi system, you can follow this method, which might be tricky and time-consuming, but it will install the latest version of Git.

Before downloading the main installation file, you should install some prerequisites needed to install Git on the Raspberry Pi system successfully. Follow the below-mentioned command to install these prerequisites on Raspberry Pi.

$ sudo apt install make libcurl4-gnutls-dev libghc-zlib-dev libssl-dev libexpat1-dev gettext -y

After installing the prerequisites, follow the below-mentioned steps to install the latest version of Git on the Raspberry Pi system.

Step 1: Download tar.gz File for Git on Raspberry Pi

First, you must download the latest version of Git tar.gz file on Raspberry Pi through the following command:

$ wget https://github.com/git/git/archive/refs/tags/v2.38.0.tar.gz

You can check for the latest version update from here and then download it accordingly.

Step 2: Extract Git tar.gz File on Raspberry Pi

To extract the contents of Git, execute the below-mentioned command:

$ tar -xf v2.38.0.tar.gz

Make sure to check the name of the tar.gz file and then replace it accordingly in the above command. The above command puts the contents of Git inside a directory “git-2.38.0”.

Step 3: Setting up Git for Raspberry Pi

To perform the Git installation, you should open the directory first through the following command:

$ cd git-2.38.0

Compile the installation files for Git through the following command:

$ sudo make prefix=/usr/local all

The compilation takes some time and once it’s finished, you can then apply the following command to install Git on your Raspberry Pi system.

$ sudo make prefix=/usr/local install

Step 3: Check Git Version on Raspberry Pi

After successfully installing Git on Raspberry Pi, you can confirm the installation of the latest version of Git on your system through the following command:

$ git --version

The above output ensures that the method successfully installed the latest version of Git on your Raspberry Pi system.

Conclusion

Installing Git on Raspberry Pi is a matter of a single command in case you are okay with installing the older version of it on your system. However, to install the latest version, you should download the tar.gz file from the GitHub source and extract its contents. To begin the installation of the latest version of Git, you must install some perquisites first before moving towards the main setup process provided in the above guidelines that use the “make” command to install Git on your Raspberry Pi system successfully.

About the author

Awais Khan

I'm an Engineer and an academic researcher by profession. My interest for Raspberry Pi, embedded systems and blogging has brought me here to share my knowledge with others.