Sub topic 5
Installing Git on your operating system
This chapter walks through installing Git on Windows, macOS, and Linux, then confirms the install worked. It assumes you can open a terminal, run simple shell commands, and know which operating system you are using. You do not need any earlier Git experience.
What you are installing
Git is a program that runs on your computer. Nothing here needs an account, a server, or a network connection after the download. The installer places a git executable on your system, and it must be reachable through your PATH. The PATH is the list of folders your shell searches when you type a command name.
Most platforms offer more than one way to install Git. This chapter uses the package manager for each platform. A package manager is a tool that downloads, installs, and updates software for you. It is the easiest route to keep Git current later.
Install commands by platform
Pick the block that matches your system. You only need one of them.
# macOS (Homebrew)
brew install git
# Debian or Ubuntu
sudo apt install git
# Fedora
sudo dnf install git
# Windows (winget)
winget install --id Git.Git -e --source wingetThe table below explains each command.
| Platform | Tool | What the command does |
|---|---|---|
| macOS | Homebrew | Downloads Git and links it into a folder already on your `PATH`. |
| Debian or Ubuntu | apt | Installs the `git` package from your distribution's repositories. |
| Fedora | dnf | Installs the `git` package from Fedora's repositories. |
| Windows | winget | Installs the official Git for Windows package. `-e` requires an exact ID match, and `--source winget` limits the search to the winget catalog. |
macOS
Homebrew is a third-party package manager for macOS. If brew is not found, install Homebrew first from its official site. macOS may also offer Git through the Xcode Command Line Tools. Running git in a fresh Terminal can prompt you to install them. That version works, but it is often older than the Homebrew one.
Linux
On Debian-based systems such as Ubuntu, apt can use stale package lists. If the install fails with a "package not found" error, refresh the lists first.
sudo apt update
sudo apt install gitOther distributions use their own tools. Arch uses pacman -S git, and openSUSE uses zypper install git. The package name is git almost everywhere.
Windows
The winget command installs Git for Windows. That package includes Git Bash, a terminal that gives you a Unix-style shell. You can also run Git from PowerShell or Command Prompt. If you prefer a graphical installer, download it from the Git for Windows project instead. The installer asks several setup questions. The defaults are reasonable for a first install, so accept them if you are unsure.
Checking that Git is installed
After the install finishes, close your terminal and open a new one. This matters because a terminal reads PATH when it starts. An already-open window may not see the new program.
Then run:
git --versionA successful result prints a version line, for example git version 2.45.1. Your number will differ, and that is fine. The output confirms two things: the program exists, and your shell can find it.
Common errors
Most install problems fall into a few patterns.
git: command not found(macOS or Linux), or'git' is not recognized(Windows). The shell cannot find Git. Open a new terminal first. If that fails, runwhich giton macOS or Linux, orwhere giton Windows, to see whether Git is on thePATHat all.sudo: command not foundor permission denied on Linux. Package installs need administrator rights. Use an account that is allowed to runsudo.brew: command not found. Homebrew is not installed, or its folder is not on yourPATH. Follow the setup steps printed at the end of the Homebrew installer.- Package not found with
apt. Runsudo apt updateand try again. - An old version appears after installing. Another copy of Git earlier in the
PATHis taking priority. Thewhich -a gitcommand on macOS and Linux lists every copy it finds, in search order.
Putting it together
The sequence is short: choose the method for your platform, run the install command, open a fresh terminal, and run git --version. Once you see a version number, Git is ready. The next steps, setting your name and email and making a first commit, build on this working install.
Exercise
You installed Git with winget, then typed git --version in the same PowerShell window that was open before the install. The shell says Git is not recognized. What is the most likely cause, and what should you try first?
Show answer
The open terminal read its PATH before Git was installed, so it does not know where the new program is. Close the window, open a new terminal, and run git --version again. If the error remains, use where git to check whether Git is on the PATH.
Exercise
On Ubuntu, sudo apt install git reports that the package cannot be found. What command do you run before retrying, and why?
Show answer
Run sudo apt update. It refreshes the local package lists that apt searches, and those lists may be missing or out of date.