Skip to content

Instantly share code, notes, and snippets.

@beattidp
Forked from egorsmkv/build-git.md
Last active October 17, 2023 18:04
Show Gist options
  • Save beattidp/486bb3f0904f3681d78849c030cb94a0 to your computer and use it in GitHub Desktop.
Save beattidp/486bb3f0904f3681d78849c030cb94a0 to your computer and use it in GitHub Desktop.
Build git from source code on CentOS 7

Build git from source code, without GUI and with Python support (e.g. git-p4)

1) Get the latest version of Git from GitHub.

Look at https://github.com/git/git/tags and toward the top pick a recent version. (e.g. at the time of this edit, v2.31.1)

method A: download a compressed archive of the sources

GITVER=2.31.1
wget https://github.com/git/git/archive/refs/tags/v${GITVER}.tar.gz
tar xf v${GITVER}.tar.gz
cd git-${GITVER}/

method B: shallow clone (assuming an earlier version of git is already installed)

Assuming you already have an earlier version of git installed, a more recent version can be pulled from GitHub, using a shallow clone/checkout of the tag.

  mkdir src-git
  cd src-git/
  git init
  git remote add origin "https://github.com/git/git.git"
  git fetch --depth 1 origin tag v2.31.1
  git checkout tags/v2.31.1

2) Install the dependencies

yum groupinstall 'Development Tools'
yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-CPAN perl-devel

3) Configure

make configure
./configure --prefix=/usr/local --with-python=`which python3`

4) Compile

PYTHON_PATH=`which python3` NO_TCLTK=1 make all

5) Install

sudo make install
@johan-boule
Copy link

The building shouldn't be done as root.
So, execute make first, then sudo make install.

@beattidp
Copy link
Author

That is correct. This is what step 4 does; builds as non-root.
(Notice the make all.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment