While Git comes pre-installed in most Linux operating systems, there might be cases when you need to install Git manually.
Unlike Mac and Windows, the easiest way to install Git on Linux is to use the command line. But since there are multiple versions of Linux, you need to learn multiple commands to install Git.
This guide will show how to install Git properly on different Linux versions. So, let’s get started.
Installing Git on Various Versions of Linux
Instead of being one operating system, Linux is a family of open-source operating systems based on the Linux kernel. You can install Git on a Linux distro by using the terminal.
These different versions of Linux are called distributions (or distros), and each distro has its own command for installing Git. So, let us look at them individually.
Here’s a table showing commands for Installing Git in multiple versions of Linux:
Linux Distros | Commands |
Ubuntu | sudo apt-get updatesudo apt-get install git |
Arch Linux | sudo pacman -S git |
CentOS | sudo yum install git |
Fedora | sudo dnf install git |
Gentoo | sudo emerge –ask –verbose dev-vcs/gitsudo pacman -S git |
RedHat | sudo dnf install git |
FreeBSD | sudo pkg update -fsudo pkg install git |
After you have installed Git, use the git –version command to verify the installation.
How to Configure Git on Linux?
You might want to configure a few things before you use Git for the first time. The git config command lets you do this. Here are some of the things you can configure:
Configurations | Commands |
View all your Git settings | git config –list –show-origin |
Set your Username and Email | git config –global user.name “Harry Potter” git config –global user.email harry@example.com |
Change Default Branch Name | git config –global init.defaultBranch main |
Change your Code Editor | git config –global core.editor “‘ full path to the executable file'” |
Launch a Git Project on Linux
To launch a Git project on Linux, go to the file directory where you want to create a new GIt repository.
For example, if your project folder is in the path /home/project/new-project, you can use the CD command in the Linux terminal to go to this folder.
Just type this command: cd /home/tp/projects
You can now initialize a Git repository with the command: git init
Doing this will give you the following output:
Initialized empty Git repository in /home/project/new-project/.git/
Frequently Asked Questions
1. Can I use Git on Linux?
Yes. Git was created for Unix-based operating systems like Linux.
2. How to verify if Git is installed on Linux?
To verify a Git installation on Linux, you can use the command git –version
3. Is Git installed on Linux by default?
In most Linux systems, Git is installed by default. But there might be some cases where you need to install Git manually.