Git is a distributed version control system that is widely used in software development and other collaborative projects. In this guide, we will cover two methods to install Git on Fedora Linux: using the official repository and compiling from the latest source code.
Prerequisites
Ensure you have a system running Fedora Linux and have superuser privileges (or sudo access).
Method 1: Installing Git from the Official Repository
This method is the easiest way to get Git up and running on your Fedora system. The official Fedora repositories contain stable versions of Git, and they ensure compatibility with the system.
- Update Your System: It’s always a good practice to update the system before installing new software.
sudo dnf update
- Install Git:
sudo dnf install git
- Verify the Installation:
git --version
This command will display the installed version of Git, ensuring that the installation process was successful.
Method 2: Installing Git from the Latest Source Code
For those who need the latest features or fixes from the Git software, compiling from source might be the preferred route. This method is a bit more involved but offers the most up-to-date version of Git.
- Install Required Dependencies: To compile Git from source, several development tools and libraries are needed. Install them using:
sudo dnf groupinstall "Development Tools"
sudo dnf install zlib-devel perl-CPAN gettext
- Download the Latest Git Source Code: Navigate to the official Git website or repository to find the link to the latest source code. Alternatively, you can use wget or curl to fetch it directly. Here’s how to do it with wget:
wget https://github.com/git/git/archive/refs/tags/v2.40.1.tar.gz
Replace 2.40.1 with the desired version number.
- Extract the Tarball and Navigate to the Directory:
tar -xvzf v2.40.1.tar.gz
cd git-2.40.1
- Compile and Install: Execute the following commands in order:
./configure --prefix=/usr
make
sudo make install
- Verify the Installation:
git --version
This command should display the version you just installed, confirming that the installation process was successful.
Conclusion
We’ve covered two methods to install Git on Fedora Linux: the first uses the official Fedora repository, while the second compiles Git from the latest source code. Depending on your needs, you can choose the method that suits you best. For most users, installing from the official repository will be sufficient, but if you need the latest and greatest features of Git, then compiling from source is the way to go.
15 Comments
This has worked fine.
But does it changes the bash_profile in user’s home directory ?
what does command “source /etc/bashrc” exactly does. ?
Also, in case if we need to revert the installed git, then what the procedure for it ?.
Thanks! Was stuck at 1.7.1 with yum update not helping. These steps got me to 2.17 in no time!
Thanks man, this really helped me on CentOS 6.9. I was struggling to update it from 1.7.1 to some newer version, and this article helps me to do it in few minutes!
Hi,
I was looking for a way how to bring latest Git to REHL 6 and there’s another, much easier way. Use Rackspace’s IUS repositories, they have rpms for latest Git version.
Regards,
P.
Can you include the full command line sequence for doing this, assuming you’re on a system that does not have those repositories?
install Rackspace repo: https://support.rackspace.com/how-to/install-epel-and-additional-repositories-on-centos-and-red-hat/
and then:
sudo yum install yum-plugin-replace
sudo yum replace git –replace-with git2u
Used this to install Git 2.7.1 on HostGator VPS running CentOS 6.5. Worked like a charm. Thank you so much.
I did the installation, everything went successfully. But now when I do git –version, it shows version 1.7.1 instead of version 2.0.5
I am getting below error… Can you help out.. I am trying this on RHEL7
[root@CTSC00541480801 git-2.5.0]# make prefix=/opt/git all
CC credential-store.o
In file included from credential-store.c:1:0:
cache.h:21:18: fatal error: zlib.h: No such file or directory
#include
^
compilation terminated.
make: *** [credential-store.o] Error 1
[root@CTSC00541480801 git-2.5.0]
Not having the zlib.h file most likely means that you didn’t install the zlib-devel package. Try doing that yum install zlib-devel step again.
Please ignore previous comment!
Great article
You may also want to update to include; yum install openssl-devel
Cheers
Hi,
This is simply amazing, it helps me a lot.
Simply luv you for this article.
Thanks buddy, it worked for me. Much appreciation!!
This worked well, thanks!
Had to ensure I exported the Git path though. In .bash_profile or other startup dotfile:
export PATH=$PATH:/usr/local/git/bin