Skip to main content
  1. Posts/

How To Install Latest Version of Git on Linux

··247 words·2 mins·
Table of Contents
Update log

2021-12-10: update endpoint rpm link for git

The version of the default git bundled with the Linux system is often too old, and lacks certain features, which may break some tools. This post summarizes how to install newer versions of Git on Linux.

Install via package manager
#

CentOS
#

If you have root rights, you can install new version of git via yum.

# https://ius.io/setup
yum install \
https://repo.ius.io/ius-release-el7.rpm \
https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

yum remove git
yum install git224

The version of git installed is 2.24.4.

The following also work:

yum -y install https://packages.endpointdev.com/rhel/7/os/x86_64/endpoint-repo.x86_64.rpm
yum remove git
yum install git

Compile and install git from source
#

First, we need to install some dependency packages. Note that if we use https protocol for git, we need to install curl development package:

yum install libcurl-devel

Otherwise, when you git clone using a https url: git clone https://xxx.xx.xx, you get an error:

git: ‘remote-https’ is not a git command. See ‘git –help’.

If you do not have root rights, you can also build curl from source.

Then, run the following script to build git from source:

wget https://github.com/git/git/archive/refs/tags/v2.31.1.tar.gz -O git.tar.gz
tar xvf git.tar.gz
cd git-*
mkdir -p $HOME/local
make configure
./configure --prefix=$HOME/local
make -j && make install

git will be installed under $HOME/local/bin. Then, add $HOME/local/bin to your PATH:

export PATH="$HOME/local/bin:$PATH"

Run git --version to check the git version.

Ref:

Related

Git line ending config
·450 words·3 mins
How to Use The Git-tag Feature
··285 words·2 mins
Git Learning Notes (3)
··481 words·3 mins