Raspberry Pi

2 Ways to Install Git on Raspberry Pi

Git is an open-source tool used for the management of source code which is free of cost and can handle small to large coding projects efficiently. It enables multiple users to work together on projects for non-linear development. The source codes developed by one user can be shared with other users to alter them and if any changes are made to the source code, the other users will get a notification of it.

This article presents a detailed guide to easily install Git on a Raspberry Pi system.

2 Easy Methods for Installing Git on Raspberry Pi

Git can be installed on Raspberry Pi from two methods, which are mentioned below:

Method 1: Installing Git from the Official Repository

Git can be installed from the official Raspberry Pi repository using the apt command. To install Git through this method, follow the below-mentioned steps:

Step 1: Update and Upgrade the Repository

Before installing any package or tool from the official repository, it is always recommended to update and upgrade the repository. So, use the update command as mentioned below to first check for packages updates:

$ sudo apt update

Then use the below-given command to upgrade the packages:

$ sudo apt upgrade

Make sure to enter “Y” to continue the upgrading process:

Once the upgrading is completed, move towards step two.

Step 2: Installing Git

After upgrading, now it is time to install Git from the official repository and for this purpose, use the following command:

$ sudo apt install git

That’s it, the installation process is completed. This is the easiest and two steps method to install Git, but the only drawback of this method is that it installs an old version of Git, which is shown below using the version command:

$ git --version

If you want to install the latest version you can opt for the next method.

Remove Git from Raspberry Pi

To go with removing Git from your Raspberry Pi system, do it by running the following command:

$ sudo apt --purge remove git -y

Method 2: Installing Git from GitHub Source

To install the latest updated version of Git, it is preferred to install it from the GitHub source. So, to perform this method, make sure to do the following steps carefully:

Step 1: Installing Dependencies

Before installing Git from the GitHub source, there are some pre-required dependencies that need to be installed first using the below-mentioned command:

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

Step 2: Downloading Git tar.gz File

Then download the latest Git tar.gz file from the below-mentioned command:

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

Note: Check for latest Git updates here.

Step 3: Extract the Downloaded File

After downloading, it is now time to extract the file, from the following command:

$ tar -xf v2.38.0.tar.gz

Step 4: Setting Up Git Installation

The downloading and extraction process is completed and it’s now time to set up Git on Raspberry Pi. For that, first, open the Git directory by using the below-mentioned command:

$ cd git-2.38.0

Now build the Git installation files using the below-mentioned command:

$ sudo make prefix=/usr/local all

As there are a lot of files, it is going to take some time to compile all of them. Once the compilation of the file is done, follow the below-mentioned command to finally install Git:

$ sudo make prefix=/usr/local install

Wait once it completes the Git installation.

Step 4: Verify Installed Version

To find out the installed version of Git, follow the below-mentioned command:

$ git --version

This above command also verifies the installation of Git on the Raspberry Pi system.

Conclusion

Git can be installed on Raspberry Pi from two ways; either from the official Raspberry Pi repository or through the GitHub source. Both these ways are explained in the above guidelines. Through the official repository, Git can be installed in just two steps but the installed version will be an old one. To install the latest version, follow the installation method from the official GitHub source.

About the author

Zahra Zamir

An Electronics graduate who loves to learn and share the knowledge, my passion for my field has helped me grasp complex electronics concepts and now I am here to share them with others.