Home » Guides » Install Git on Linux, Ubuntu, Fedora, Gentoo, Arch, OpenSUSE, etc.

Install Git on Linux, Ubuntu, Fedora, Gentoo, Arch, OpenSUSE, etc.

Git is important to coders. And Linux being one of the top OSes in the world, and a favorite of developers, equally requires a version control system that can allow them to track file changes. Git is at the forefront of such version control systems as they work by creating various collections of files and recording changes made to each version over time. As such, installing Git on Linux will allow developers to switch between the different versions of the files effortlessly.

What is Git?

Linus Torvalds is the person credited for the development of Git back in the year 2005. Since then, it has kept on growing as more and more developers find the software user-friendly and efficient as a version control system. And due to it being free and open-sourced to boot over that, Git enjoys a thriving community that contributes to its success.

Git Logo

As a version control system, Git is capable of handling anything, irrespective of the scale, involving file changes. Thus, it is able to handle small or large products with sufficient speed and efficiency. Furthermore, since Git can track changes in computer files, employers can use the software to coordinate work among programmers to develop source codes during a project development phase.

Git aims to achieve speed while maintaining data integrity and supports distributed non-linear workflows.

Here is an amazing video by Programming with Mosh channel explaining Git in detail –

What is Git? Explained in 2 Minutes!

Uses of Git

Using Git can be a difficult process, especially for beginners. However, once you get used to it, Git can be an amazing tool. Here we listed some of the best uses of Git.

1. Version Control

Firstly, Git allows you to keep a history of changes to your code. This can be extremely beneficial in a lot of scenarios. For example, imagine you’re working on a project. You made some changes to the code that didn’t quite work out. If you have Git installed, you can easily roll back to a previous, working version of your code with a click of a button. It’s like having a safety net for your project.

2. Collaboration

If you are working with a team, Git makes collaboration a breeze. Using Git, multiple people can work on the same project simultaneously, and Git helps merge their changes together seamlessly as well. No more stepping on each other’s toes!

3. Branching

Git lets you create branches, which are like parallel universes for your code. You can work on new features or bug fixes in separate branches without affecting the main codebase. This is an extremely important feature for any large project.

Once your changes are ready, you can merge them back in. It’s a neat way to keep things organized.

4. Remote Repositories

It can sync your code with remote repositories like GitHub, GitLab, or Bitbucket (or anything else that is supported by the tool). This means you can work on your code from anywhere and collaborate with developers from all over the world no matter where you are.

5. Open Source Contributions

If you’re into open source, Git is your best friend. You can fork repositories, make changes, and then create pull requests to contribute your improvements to the original project. Contributing to open source can build your portfolio, making it easier to get jobs in the future.

6. Backup

Git also acts as a backup system. By pushing your code to a remote repository, you ensure that your precious work is safe even if your local machine decides to take a vacation for some reason.

7. Experimentation

Want to experiment with a new idea or feature? Create a branch, tinker away, and if it doesn’t work out, you can simply delete the branch. No harm done! As simple as that.

8. Documentation

Git can be used to track changes in documentation and writing projects, making it handy for writers. You can see who made what changes and when without having to reach out to them every single time.

Prerequisites to installing Git on Linux

Installing Git on any Linux distro is no chore, all the user has to do is:

  • Ensure he has a working internet connection.
  • Required free disk space.
  • And access (preferably root access) to a Linux system.
Linux DistributionInstallation Method
Debian/UbuntuUsing Package Manager
FedoraUsing Package Manager
GentooUsing Package Manager
Arch LinuxUsing Package Manager
openSUSEUsing Package Manager
MageiaUsing Package Manager
NixOSUsing Package Manager
FreeBSDUsing Package Manager
Solaris 9/10/11/ExpressUsing Package Manager
OpenBSDUsing Package Manager
AlpineUsing Package Manager
SlitazUsing Package Manager
Other DistributionsBuilding from Source

Methods to install Git

There are several methods you can follow to install Git on Linux. The steps you have to follow will depend on the type of Linux distribution you are using and the features you might need. Follow the methods mentioned below based on your needs, starting from the top to the bottom.

Method 1. Using the preferred package managers

The first method is the easiest and preferred solution for Git installation. All the user has to do is access the command terminal and the system repository. We have included the installation command required for the different distros in the following segment.

Note – The underlining installation process remains the same and will not be repeated.

Installing Git on Debian/Ubuntu

Step 1. Launch the command terminal using Ctrl + Alt + T.

Step 2. Update the APT repository if needed:

sudo apt update
sudo apt-get update

Step 3. Install Git.

sudo apt install git

or

sudo apt-get install git

Fedora

The first few steps remain the same for Fedora. However, the installation command changes to either YUM or DNF, depending on your system version.

On Fedora 21 or older:
sudo yum install git
On fedora 22 and later:
sudo dnf install git

Note – The rest of the distros mentioned here use the similar first few steps. Only the actual installation code differs.

Gentoo

emerge --ask --verbose dev-vcs/git

Arch Linux

pacman -S git

openSUSE

zypper install git

Mageia

urpmi git

NixOS

nix-env -i git

FreeBSD

pkg install git

Solaris 9/10/11/Express

pkgutil -i git

or

pkg install developer/versioning/git

OpenBSD

pkg_add git

Alpine

apk add git

Slitaz

tazpkg get-install git

Method 2. Install Git by Building from Source

For advanced users, they can modify or customize the file during installation when it is built from source. However, binary installations are a bit behind times, especially in recent years as Git has matured. Thus, in order to build a working Git on a Linux distro users are required to install a few Git-dependent libraries such as: autotools, curl, zlib, openssl, expat, and libiconv. Given below is the entire installation process for different distros.

On Debian/Ubuntu

Step 1. Launch the command terminal.

Step 2. Now install the required libraries and dependencies:

sudo apt-get install dh-autoreconf libcurl4-gnutls-dev libexpat1-dev \ gettext libz-dev libssl-dev
sudo apt-get install asciidoc xmlto docbook2x

Step 3. Next, the user is required to install the install-info package:

sudo apt-get install install-info

Step 4. Then, download the latest tagged release tarball either from the Kernel website or GitHub.

Step 5. Now decompress the .tar file:

tar -zxf git-2.8.0.tar.gz

Step 6. Finally, compile the build using CD and MAKE command:

cd git-2.8.0
make configure
./configure --prefix=/usr
make all doc info

Step 7. And lastly, install the build.

sudo make install install-doc install-html install-info

On Fedora

On Fedora the installation process remains the same as Debian/Ubuntu after Step 4. The rest of the process is described below:

Step 1. Start the command terminal.

Step 2. Then, install the required dependencies:

sudo dnf install dh-autoreconf curl-devel expat-devel gettext-devel
\ openssl-devel perl-devel zlib-devel
sudo dnf install asciidoc xmlto docbook2X

Step 3. Instead of the install-info package, Fedora users need the getopt package.

sudo dnf install getopt

The rest of the steps are the same for Fedora as it was on Debian/Ubuntu.

How to Check if Git is Installed

After installing Git, make sure that the installation was successful by running the following command in the terminal –

git --version

The output of this command should look something like this –

git version 2.33.0

Configure Git after Successful installation

Installing git may not be enough for you to seamlessly utilize its features. Hence, you should configure things such as your repository username and email.

Configure username and email

git config --global user.name "Your Name"
git config --global user.email "[email protected]"

Set preferred text editor for Git

You can set VS Code as the default Git editor using the following command –

git config --global core.editor "code --wait"

Configure Line Bindings

If you’re working on a cross-platform project, you might want to configure how Git handles line endings. If not, it might create issues, especially if you have a team working from different operating systems. On Windows, you can set it to autocrlf, and on macOS/Linux, you can set it to input:

git config --global core.autocrlf input

Once you have made all the configuration changes based on your preferences, you can verify everything running this command.

git config --list

Git Commands for Common Version Control Tasks

In order to start using Git to control your code versions, you should be familiar with these Git commands –

TaskGit Command
Initialize a new Git repositorygit init
Clone a remote repositorygit clone <repository_url>
Create a new branchgit checkout -b <branch_name>
Switch to an existing branchgit checkout <branch_name>
Stage changes for commitgit add <file_or_directory>
Commit changes with a messagegit commit -m "Commit message"
Push changes to a remote repogit push <remote_name> <branch_name>
Pull changes from a remote repogit pull <remote_name> <branch_name>
View commit historygit log
Create a Git taggit tag <tag_name>
Merge changes from another branchgit merge <branch_name>
Discard changes in working dirgit checkout -- <file_or_directory>

The best Git Hosting Platforms

There are many Git hosting platforms available to make it easier to work with Git. Based on our research and experience, the following are the best in the industry –

PlatformDescription
GitHubThe most popular platform for code hosting and collaboration.
GitLabOffers both cloud-hosted and self-hosted Git repository options.
BitbucketProvides Git and Mercurial repository hosting.
SourceForgeSupports Git for hosting open-source projects.
Azure DevOpsIntegrated development platform by Microsoft, includes Git hosting.
GitKrakenGit GUI client with built-in Git repository hosting.
GitBucketLightweight and open-source Git platform written in Scala.

FAQs about Git Installation

How do I check if Git is already installed?

You can check if Git is installed by opening your command line or terminal in your Linux distribution and running the command git --version. If Git is installed, it will display the installed version. If not, it will suggest installing it.

Do I need to install Git for every project?

No, you only need to install Git once on your Linux device. You can use Git for multiple projects without reinstalling it over and over again.

How do I install a specific version of Git?

If you want to install a specific version of Git, you can use the package manager’s version specifier. For example, to install Git version 2.30, you can use:

sudo apt install git=2.30

How do I update Git to the latest version?

You can update Git to the latest version using your package manager. For example:

sudo apt update
sudo apt upgrade git

How do I check the Git version I’m using?

You can check the Git version by running the following command:

git --version

Can I use Git without an internet connection?

Yes, Git is a distributed version control system, so you can use it locally without an internet connection. However, you will need an internet connection to clone remote repositories or push changes to remote repositories.

How can I find more information about Git commands and usage?

You can use the git --help command to get information about Git commands, and you can also refer to the Git documentation or online tutorials for more in-depth information on using Git.

Gilbert John Avatar