Git is a widely-used version control system that allows you to track changes in your codebase and collaborate with others. This guide will walk you through the steps to install Git on various Linux distributions.
Installing Git on Ubuntu
To install Git on Ubuntu, follow these steps:
Update the package index:
Terminalsudo apt updateInstall Git:
Terminalsudo apt install gitVerify the installation:
Terminalgit --versionYou should see the installed Git version.
Installing Git on Debian
Debian is another widely-used Linux distribution. Here’s how you can install Git on Debian:
Update the package index:
Terminalsudo apt updateInstall Git:
Terminalsudo apt install gitVerify the installation:
Terminalgit --versionYou should see the installed Git version.
Installing Git on Fedora
For Fedora users, the installation process is slightly different. Follow these steps:
Update the package index:
Terminalsudo dnf updateInstall Git:
Terminalsudo dnf install gitVerify the installation:
Terminalgit --versionYou should see the installed Git version.
Installing Git on CentOS
CentOS users can install Git by following these steps:
Install the required dependencies:
Terminalsudo yum groupinstall "Development Tools"sudo yum install gettext-devel openssl-devel perl-CPAN perl-devel zlib-develDownload the latest Git source code:
Terminalwget https://github.com/git/git/archive/v2.34.1.tar.gz -O git.tar.gzExtract the downloaded file:
Terminaltar -zxf git.tar.gzcd git-2.34.1Compile and install Git:
Terminalmake prefix=/usr/local allsudo make prefix=/usr/local installVerify the installation:
Terminalgit --versionYou should see the installed Git version.
Configuring Git
After installing Git, you should configure your Git environment. Follow these steps:
Set your username:
Terminalgit config --global user.name "Your Name"Set your email:
Terminalgit config --global user.email "your.email@example.com"Verify your configuration:
Terminalgit config --listYou should see your username and email configured.
Installing Git from source
If you need a specific version of Git or want to install the latest version, you can install Git directly from the source code. Follow these steps:
Install the required dependencies:
On Ubuntu/Debian:
Terminalsudo apt updatesudo apt install make libssl-dev libghc-zlib-dev libcurl4-gnutls-dev libexpat1-dev gettext unzipOn Fedora:
Terminalsudo dnf install dh-autoreconf curl-devel expat-devel gettext-devel openssl-devel perl-devel zlib-develsudo dnf install asciidoc xmlto docbook2XDownload the latest Git source code:
Terminalwget https://github.com/git/git/archive/v2.34.1.tar.gz -O git.tar.gzExtract the downloaded file:
Terminaltar -zxf git.tar.gzcd git-2.34.1Compile and install Git:
Terminalmake prefix=/usr/local allsudo make prefix=/usr/local installVerify the installation:
Terminalgit --versionYou should see the installed Git version.
Troubleshooting common issues
Here are some common issues you might encounter during installation and their solutions:
Permission denied errors:
Ensure you are using
sudo
to install Git. For example:Terminalsudo apt install gitCommand not found:
Ensure that Git is installed correctly and added to your system’s PATH. Verify the installation with:
Terminalgit --version
For further information see the official Git documentation.