Lesson 4 of 6815 min read

Installing Git: Windows (Git Bash), macOS (Homebrew), and Linux (apt/yum)

Step-by-step instructions to install Git on Windows, macOS, and Linux, plus how to verify your installation succeeded.

Author: CodersNexus

Installing Git: Windows (Git Bash), macOS (Homebrew), and Linux (apt/yum)

Before you can run a single Git command, Git needs to be installed on your machine. The installation process differs across operating systems, and each platform has its own recommended method: Git Bash on Windows, Homebrew on macOS, and native package managers like apt or yum on Linux. This lesson walks through all three so that no matter what machine you're using, you'll have a working Git installation and know how to confirm it.

Learning Objectives

  • Install Git on Windows using the official Git for Windows installer (Git Bash).
  • Install Git on macOS using Homebrew.
  • Install Git on Linux using apt (Debian/Ubuntu) or yum (RHEL/CentOS/Fedora).
  • Verify a successful installation using git --version.

Key Terms to Know Before Learning Installing Git

  • Git Bash: A terminal application bundled with Git for Windows that provides a Unix-like command-line environment, letting Windows users run standard Git and shell commands.
  • Homebrew: A popular free and open-source package manager for macOS (and Linux) used to install and manage command-line tools like Git.
  • Package manager: A tool that automates installing, upgrading, and removing software, resolving dependencies automatically (e.g., apt, yum, Homebrew).
  • apt (Advanced Package Tool): The default package manager used on Debian-based Linux distributions, including Ubuntu.
  • yum / dnf: Package managers used on Red Hat-based Linux distributions such as RHEL, CentOS, and Fedora (dnf being the modern successor to yum).

How Installing Git Actually Works

**On Windows**, the recommended way to install Git is via the official Git for Windows installer, downloaded from git-scm.com. This installer bundles Git Bash, a terminal emulator that mimics a Unix/Linux shell — this matters because nearly all Git tutorials, documentation, and command examples (including this course) assume a Unix-style command line, and Git Bash lets Windows users follow along exactly. During installation, you'll be asked several configuration questions (default editor, line-ending handling, PATH environment settings) — for beginners, the default recommended options are almost always safe to accept.

**On macOS**, the cleanest installation method is via Homebrew, the most widely used package manager for the platform. If Homebrew isn't already installed, it can be installed with a single terminal command from brew.sh. Once Homebrew is set up, installing Git is a single `brew install git` command. macOS also ships with an older version of Git bundled via Xcode Command Line Tools, but using Homebrew ensures you get a current, easily upgradable version.

**On Linux**, Git is installed through your distribution's native package manager. Debian-based distributions (Ubuntu, Debian, Linux Mint) use `apt`, while Red Hat-based distributions (RHEL, CentOS, Fedora, Rocky Linux) use `yum` or the newer `dnf`. Because Git is such a foundational tool, it's available directly in the default repositories of virtually every Linux distribution.

Regardless of platform, after installation you should always verify it succeeded by opening a terminal and running `git --version`. This should print a version number (e.g., `git version 2.44.0`). If the command isn't recognized, the most common cause is that Git wasn't added to your system's PATH environment variable during installation — reinstalling and selecting the 'Git from the command line' PATH option (on Windows) usually resolves this.

Installing Git: Visual Walkthrough

Show three parallel vertical install paths labeled 'Windows', 'macOS', and 'Linux'. Windows path: 'Download installer from git-scm.com' → 'Run installer, accept defaults' → 'Open Git Bash'. macOS path: 'Install Homebrew (if needed)' → 'brew install git' → 'Open Terminal'. Linux path: 'sudo apt update' or 'sudo yum check-update' → 'sudo apt install git' or 'sudo yum install git' → 'Open Terminal'. All three paths converge into one final box: 'Run: git --version to verify'.

Installing Git: Quick Reference Table

OSInstall MethodCommandTerminal Used
WindowsOfficial installer from git-scm.comRun the .exe installerGit Bash
macOSHomebrew package managerbrew install gitTerminal / iTerm
Linux (Debian/Ubuntu)APT package managersudo apt update && sudo apt install gitTerminal
Linux (RHEL/CentOS/Fedora)YUM / DNF package managersudo yum install git (or dnf)Terminal

Installing Git: Command Syntax and Examples

# ── Windows (inside Git Bash, after installer completes) ──
git --version

# ── macOS ──
# 1. Install Homebrew if not already installed:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# 2. Install Git:
brew install git
# 3. Verify:
git --version

# ── Linux (Debian/Ubuntu) ──
sudo apt update
sudo apt install git -y
git --version

# ── Linux (RHEL/CentOS/Fedora) ──
sudo yum install git -y
# or, on newer systems:
sudo dnf install git -y
git --version

Breaking Down the Installing Git Example

Each block reflects the standard installation flow for that operating system. Windows users run the official graphical installer and then verify from within Git Bash. macOS users first ensure Homebrew is available, then run a single `brew install git` command. Linux users update their package index (`apt update` or `yum check-update`) before installing, which ensures they get the latest available version from their distribution's repositories. In every case, the final `git --version` command is the universal way to confirm installation succeeded — if it prints a version number like `git version 2.44.0`, Git is ready to use.

How Installing Git Is Used on Real Engineering Teams

  • Corporate IT departments often pre-install Git via managed software deployment tools (like Intune for Windows or Jamf for macOS) so new developer laptops are Git-ready on day one.
  • DevOps engineers frequently install Git as part of automated server provisioning scripts (using apt/yum) so that CI/CD build servers can clone repositories without manual setup.
  • Docker images for development environments almost always include a Git installation step (e.g., `RUN apt-get install -y git`) so containers can clone source code during builds.
  • Cloud-based development environments like GitHub Codespaces and GitPod come with Git pre-installed, reflecting how fundamental it is considered to any coding environment.

Installing Git Interview Questions and Answers

Q1. How do you install Git on Windows, macOS, and Linux?

On Windows, download and run the official installer from git-scm.com, which also installs Git Bash. On macOS, use Homebrew with `brew install git`. On Linux, use the distribution's package manager — `sudo apt install git` for Debian/Ubuntu-based systems, or `sudo yum install git` (or `dnf`) for Red Hat-based systems.

Q2. How do you verify that Git was installed correctly?

Open a terminal (or Git Bash on Windows) and run `git --version`. If Git is installed and available in the system PATH, this prints a version number such as `git version 2.44.0`. If the command isn't recognized, Git likely wasn't added to the PATH during installation.

Q3. What is Git Bash and why is it recommended on Windows?

Git Bash is a terminal application bundled with Git for Windows that provides a Unix-like shell environment. It's recommended because most Git tutorials and documentation assume Unix-style commands, and Git Bash lets Windows users run those commands exactly as written, unlike the native Windows Command Prompt.

Installing Git Quiz: Test Your Understanding

1. What command is used to install Git via Homebrew on macOS?

  1. brew get git
  2. brew install git
  3. brew add git
  4. install git --homebrew

Answer: B. brew install git

Explanation: Homebrew uses the `install` subcommand to install any package, so `brew install git` is the correct command.

2. Which terminal application is bundled with the official Git installer on Windows?

  1. PowerShell
  2. Command Prompt
  3. Git Bash
  4. WSL

Answer: C. Git Bash

Explanation: Git Bash is included with Git for Windows and provides a Unix-like shell so Windows users can run standard Git commands as documented.

3. Which command verifies that Git has been installed correctly on any operating system?

  1. git check
  2. git --version
  3. git status
  4. git verify

Answer: B. git --version

Explanation: `git --version` prints the installed Git version, confirming both that Git is installed and that it is accessible from the command line.

4. Which package manager is used to install Git on Ubuntu?

  1. yum
  2. dnf
  3. apt
  4. brew

Answer: C. apt

Explanation: Ubuntu is a Debian-based distribution, which uses `apt` (Advanced Package Tool) as its default package manager.

Installing Git: Common Mistakes Beginners Make

  • Forgetting to select 'Git from the command line and also from 3rd-party software' during the Windows installer's PATH step, causing `git` to be unrecognized outside Git Bash.
  • Running `brew install git` without first installing Homebrew itself, resulting in a 'command not found: brew' error.
  • Forgetting to run `sudo apt update` before `sudo apt install git`, which can install an outdated cached version on Linux.
  • Assuming macOS's built-in Git (from Xcode Command Line Tools) is always up to date — it can lag significantly behind the latest release.

Installing Git: Exam-Ready Quick Notes

  • Windows: official installer from git-scm.com, bundles Git Bash.
  • macOS: Homebrew — `brew install git`.
  • Linux: `apt` for Debian/Ubuntu, `yum`/`dnf` for RHEL/CentOS/Fedora.
  • Universal verification command: `git --version`.

Installing Git: Key Takeaways

  • Each operating system has a distinct, standard method for installing Git — no single universal installer exists across platforms.
  • Git Bash is the recommended terminal on Windows because it matches the Unix-style commands used in Git documentation and tutorials worldwide.
  • Always verify installation with `git --version` before proceeding to configuration and your first repository.

Frequently Asked Questions About Installing Git

Q1. How do I install Git on Windows?

Download the official installer from git-scm.com, run it, and accept the recommended default options during setup. This also installs Git Bash, a terminal you'll use to run Git commands.

Q2. Do I need Homebrew to install Git on a Mac?

It's the recommended method because it makes future updates easy, but macOS also includes a version of Git through Xcode Command Line Tools. Homebrew is preferred because it stays more current and is easier to manage alongside other development tools.

Q3. What is the difference between apt and yum?

Both are package managers used to install software on Linux, but `apt` is used on Debian-based distributions like Ubuntu, while `yum` (and its modern replacement, `dnf`) is used on Red Hat-based distributions like CentOS, RHEL, and Fedora.

Q4. How do I check which version of Git I have installed?

Run `git --version` in your terminal or Git Bash. It will print something like `git version 2.44.0`, confirming both the installed version and that Git is properly available on your system's PATH.

Q5. What should I do if 'git' is not recognized as a command after installing?

This usually means Git wasn't added to your system's PATH environment variable. On Windows, reinstall and choose the option to use Git from the command line during setup. On macOS/Linux, ensure the installation completed without errors and restart your terminal.

Summary

Installing Git differs by operating system: Windows users install via the official git-scm.com installer, which bundles the Git Bash terminal for a Unix-like command-line experience; macOS users typically install via Homebrew with a single `brew install git` command; and Linux users install through their distribution's native package manager, using `apt` on Debian/Ubuntu systems or `yum`/`dnf` on Red Hat-based systems. Regardless of platform, `git --version` is the universal command to confirm a successful installation before moving on to configuring Git and creating your first repository.

Frequently Asked Questions

Download the official installer from git-scm.com, run it, and accept the recommended default options during setup. This also installs Git Bash, a terminal you'll use to run Git commands.

It's the recommended method because it makes future updates easy, but macOS also includes a version of Git through Xcode Command Line Tools. Homebrew is preferred because it stays more current and is easier to manage alongside other development tools.

Both are package managers used to install software on Linux, but `apt` is used on Debian-based distributions like Ubuntu, while `yum` (and its modern replacement, `dnf`) is used on Red Hat-based distributions like CentOS, RHEL, and Fedora.

Run `git --version` in your terminal or Git Bash. It will print something like `git version 2.44.0`, confirming both the installed version and that Git is properly available on your system's PATH.

This usually means Git wasn't added to your system's PATH environment variable. On Windows, reinstall and choose the option to use Git from the command line during setup. On macOS/Linux, ensure the installation completed without errors and restart your terminal.