How to Install Git on Linux: Simple Steps for Beginners
To install
git on Linux, use your distribution's package manager. For Debian/Ubuntu, run sudo apt update && sudo apt install git. For Red Hat/CentOS, use sudo yum install git.Syntax
Use your Linux distribution's package manager to install git. The common commands are:
- Debian/Ubuntu:
sudo apt updateupdates package info, andsudo apt install gitinstalls Git. - Red Hat/CentOS:
sudo yum install gitinstalls Git directly.
bash
sudo apt update sudo apt install git
Example
This example shows how to install Git on Ubuntu Linux. It updates the package list and installs Git.
bash
sudo apt update sudo apt install git git --version
Output
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
git
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 21.1 MB of archives.
After this operation, 80.3 MB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu focal/main amd64 git amd64 1:2.25.1-1ubuntu3.10 [21.1 MB]
Fetched 21.1 MB in 2s (10.5 MB/s)
Selecting previously unselected package git.
(Reading database ... 123456 files and directories currently installed.)
Preparing to unpack .../git_1%3a2.25.1-1ubuntu3.10_amd64.deb ...
Unpacking git (1:2.25.1-1ubuntu3.10) ...
Setting up git (1:2.25.1-1ubuntu3.10) ...
Processing triggers for man-db (2.9.1-1) ...
git version 2.25.1
Common Pitfalls
Common mistakes when installing Git on Linux include:
- Not running
sudo apt updatebefore installing, which can cause package not found errors. - Using the wrong package manager for your Linux distribution.
- Trying to install Git without sufficient permissions (missing
sudo).
bash
Wrong (missing update): apt install git Right: sudo apt update sudo apt install git
Quick Reference
| Linux Distribution | Install Command |
|---|---|
| Debian/Ubuntu | sudo apt update && sudo apt install git |
| Red Hat/CentOS | sudo yum install git |
| Fedora | sudo dnf install git |
| Arch Linux | sudo pacman -S git |
Key Takeaways
Use your Linux distribution's package manager to install Git with sudo permissions.
Always run the update command before installing packages to get the latest info.
Choose the correct package manager command for your Linux version.
Verify installation by running git --version after installing.