Skip to content

Instantly share code, notes, and snippets.

@k8scat
Last active June 13, 2021 17:35
Show Gist options
  • Save k8scat/eda787a71d8f327134a0b5508569e451 to your computer and use it in GitHub Desktop.
Save k8scat/eda787a71d8f327134a0b5508569e451 to your computer and use it in GitHub Desktop.
Install git from source code on CentOS 7.
#!/bin/bash
#
# Install git from source code on CentOS 7, refer to https://github.com/git/git/blob/master/INSTALL
set -e
# Get version from https://github.com/git/git/releases, for example: 2.29.2
version=$1
if [[ -z "${version}" ]]; then
echo "usage: $0 <version, 2.29.2> [profile]"
exit 1
fi
if [[ $(id -u) -ne 0 ]]; then
echo "require root"
exit 1
fi
yum install -y make \
gcc \
openssl-devel \
expat-devel \
curl-devel \
gettext-devel \
tcl-devel
git_pkg="v${version}.tar.gz"
curl -LO https://github.com/git/git/archive/v${version}.tar.gz
git_dir="git-${version}"
tar zxf v${version}.tar.gz
cd ${git_dir}
if [[ "$2" = "profile" ]]; then
# This will run the complete test suite as training workload and then
# rebuild git with the generated profile feedback. This results in a git
# which is a few percent faster on CPU intensive workloads. This
# may be a good tradeoff for distribution packagers.
#
# If you're willing to trade off (much) longer build time for a later
# faster git you can also do a profile feedback build with
make prefix=/usr profile
make prefix=/usr PROFILE=BUILD install
else
# Normal installation
make prefix=/usr
make prefix=/usr install
fi
cd -
rm -rf ${git_dir}
rm -f ${git_pkg}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment