How to Install Git on Raspberry Pi

By 

Updated on

4 min read

Installing Git on Raspberry Pi OS using the terminal

Git is a distributed version control system used by most software teams today. It allows you to keep track of your code changes, revert to previous stages, create branches , and collaborate with your fellow developers.

Git was originally developed by Linus Torvalds , the creator of the Linux kernel.

This guide explains how to install Git on Raspberry Pi OS. It assumes you have Raspberry Pi OS installed on your Raspberry Pi .

For most users, the easiest and recommended way to install Git is through the apt package manager. If you need the latest stable version, scroll down to the Installing Git from Source section.

Quick Reference

For a printable quick reference, see the Git cheatsheet .

CommandDescription
sudo apt install gitInstall Git from the Raspberry Pi OS repositories
git --versionVerify the installed version
git config --global user.name "Name"Set your commit name
git config --global user.email "email"Set your commit email
git config --listView current Git configuration

Installing Git with Apt

The Git package is included in the Raspberry Pi OS default repositories.

Run the following commands as root or a user with sudo privileges to install Git:

Terminal
sudo apt update
sudo apt install git

Once the installation is complete, verify it by running:

Terminal
git --version
output
git version 2.39.2

Git is now installed and ready to use.

Installing Git from Source

Compiling Git from source allows you to install the latest version and customize build options. However, a source-based installation is not managed by apt, so updates require repeating the build process manually.

Start by installing the build dependencies:

Terminal
sudo apt update
sudo apt install make libssl-dev zlib1g-dev libcurl4-gnutls-dev libexpat1-dev gettext

Next, visit the Git releases page on GitHub and note the latest release tag. Set that version in the GIT_VERSION variable in the command below. We are downloading the source to /usr/src, a common location for source files:

Terminal
cd /usr/src/
GIT_VERSION="X.Y.Z"
sudo wget "https://github.com/git/git/archive/v${GIT_VERSION}.tar.gz" -O git.tar.gz

Extract the archive and change to the source directory:

Terminal
sudo tar -xf git.tar.gz
cd "git-${GIT_VERSION}"

Compile and install Git:

Terminal
sudo make prefix=/usr/local all
sudo make prefix=/usr/local install

Verify the installation:

Terminal
git --version

To update Git in the future, download the newer release archive from the releases page and repeat the build process.

Configuring Git

After installation, set your identity. Git attaches this information to every commit you make.

Terminal
git config --global user.name "Your Name"
git config --global user.email "youremail@yourdomain.com"

To confirm the settings, run:

Terminal
git config --list
output
user.name=Your Name
user.email=youremail@yourdomain.com

The configuration is stored in the ~/.gitconfig file:

~/.gitconfigconf
[user]
    name = Your Name
    email = youremail@yourdomain.com

For more options, see How to Configure Git Username and Email .

Troubleshooting

git: command not found after a source install
The source installation places the binary in /usr/local/bin. Run echo $PATH to confirm that directory is included. If it is missing, add export PATH="/usr/local/bin:$PATH" to ~/.bashrc and reload with source ~/.bashrc.

Build fails with missing dependency errors
Ensure all build dependencies installed without errors before compiling. Re-run the apt install command from the source section, check the output for any failures, and retry.

The apt version is older than expected
The Raspberry Pi OS repositories do not always ship the latest Git release. If you need a newer version than apt provides, use the source installation method instead.

git config settings are not taking effect
The --global flag writes to ~/.gitconfig and applies to all repositories for your user. Without it, settings apply only to the current repository. Run git config --list --show-origin to see which config files are active and where they are stored.

FAQ

Should I install from apt or from source?
Use apt for most cases. It is simpler, the package manager handles updates, and security patches are applied automatically. Install from source only when you need a version newer than what the repositories provide.

How do I update Git installed from source?
Download the newer release archive from the Git releases page , extract it, and repeat the make commands. The new binary replaces the previous one in /usr/local/bin.

How do I uninstall Git?
If installed via apt, run sudo apt remove git. If installed from source, remove the binary manually with sudo rm /usr/local/bin/git along with any associated files in /usr/local.

Can I use Raspberry Pi as a Git server?
Yes. With a minimal server setup you can set up your own Git server on your local network using your Raspberry Pi.

Conclusion

You have installed Git on Raspberry Pi OS using apt or built the latest version from source. Set your identity with git config before making your first commit.

If you have any questions, feel free to leave a comment below.

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page