W3docs

Install Git

On this page, you will find useful information about Git installation learning how to install Git from source; how to install it on Mac, Windows and Linux.

Working with Git starts with installing or updating it, if you already have it on your computer. On this page, you will find how to install Git on Windows, Linux and Mac.

how to install git

How to Install Git on Mac

There are three ways to install Git on Mac OS X: Git for Mac installer, Homebrew and MacPorts.

Mac Installer

This is the simplest way of installing Git on Mac. Here are the steps to follow:

  1. Download the latest Git for Mac installer.
  2. Follow the given instructions to finish installing.
  3. Open the terminal and type git --version to verify that the installation was successful.
git --version
git version 2.9.2
  1. Enter your Git username and email as given in the example below:

Install Git on Mac

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

Homebrew

Install Homebrew on Mac and then follow the steps below to install Git with it:

  1. Open your terminal and install Git with Homebrew.

Installing Git via Homebrew

brew install git
  1. Type git --version to verify that the installation was successful.

Install Git with Homebrew

git --version
git version 2.9.2
  1. You need to enter your Git username and email as given in the example below:

Setting Git username and email

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

MacPorts

Follow these instructions to install Git with MacPorts:

  1. Update MacPorts:

Install Git with MacPorts

sudo port selfupdate
  1. Now you need to search the most recent Git ports and variants:

Install Git

port search git
port variants git
  1. The installation of Git should include bash completion, the OS X keychain helper, and the docs:

Installing Git with OS X keychain helper

sudo port install git +bash_completion +credential_osxkeychain +doc
  1. You need to configure your Git username and email as given in the example below:

Install Git

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

How to Install Git on Windows

Find the instructions below to install Git on Windows:

  1. Download the most recent Git for Windows installer.
  2. Then, the Git Setup wizard screen will show up and you need to follow the prompts to complete the installation.
  3. Open a Command Prompt or Git Bash if you’ve selected not to use Git from Windows Command Prompt.
  4. Configure your Git username and email as given in the example below:

Install Git on Windows

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

How to Install Git on Linux

Debian / Ubuntu ( apt-get )

You can find Git packages via APT. Here are the steps to follow:

  1. Install Git from your shell with apt-get:

Install Git on Linux

sudo apt-get update
sudo apt-get install git
  1. Type git --version to verify that the installation has succeeded:

git --version

git --version
git version 2.9.2
  1. Enter your Git username and email as given in the example below:

Install Git

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

Fedora (dnf/yum)

Git packages are available via dnf. (Note: yum is deprecated in modern Fedora.)

  1. Install Git using dnf:

Install Git via dnf

sudo dnf install git
  1. Type git --version to verify that the installation was successful.

Check git version

git --version
git version 2.9.2
  1. Configure your Git username and email as given in the example below:

Install Git

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

How to Install Git From Source on Linux

Installing Git from source is preferable, as you can always get the latest version. You need the following libraries to install Git from source: curl, zlib, openssl, expat and libiconv. For those who use a system that has dnf or apt-get, the two commands below can be useful for installing all of the dependencies:

Note that you will need the following additional dependencies to be able to add documentation in different formats (doc, HTML, info):

Install Git From Source

sudo yum install curl-devel expat-devel gettext-devel \
openssl-devel zlib-devel perl-devel asciidoc xmlto

Install Git From Source

sudo apt-get install libcurl4-openssl-dev libexpat1-dev gettext \
libz-dev libssl-dev

Install Git and add documentation formats

sudo dnf install asciidoc xmlto docbook2X
sudo apt-get install asciidoc xmlto docbook2x

Compile and install:

Install Git, Compile and install

tar -zxf git-<version>.tar.gz
cd git-<version>
make prefix=/usr/local all
sudo make prefix=/usr/local install

After installation, verify that Git is in your PATH by running git --version. If the command is not found, add /usr/local/bin to your PATH environment variable.

You can also fetch the latest source code directly using Git:

Fetching source code

git clone https://github.com/git/git.git

Practice

Practice

Which methods can be used to install Git on different operating systems?