# 仓库版本的安装
apt-get install git
# 最新版本的安装,for Ubuntu
add-apt-repository ppa:git-core/ppa
apt update
apt install git
yum install -y https://repo.ius.io/ius-release-el7.rpm
yum install -y epel-release
# re-install git:
yum erase -y git*
yum install -y git-core
还可以尝试通过商业公司的源安装git
# yum install http://opensource.wandisco.com/centos/6/git/x86_64/wandisco-git-release-6-1.noarch.rpm
# yum install http://opensource.wandisco.com/centos/7/git/x86_64/wandisco-git-release-7-1.noarch.rpm
yum install -y http://opensource.wandisco.com/centos/7/git/x86_64/wandisco-git-release-7-2.noarch.rpm
yum makecache
yum install -y git
当多个源中软件版本有冲突时可以指定禁用和启用那个源
#查看源对应的版本
yum provides git
git-1.8.3.1-23.el7_8.x86_64 : Fast Version Control System
源 :base
git236-2.36.1-2.el7.ius.x86_64 : Fast Version Control System
源 :ius
匹配来源:
提供 :git = 2.36.1-2.el7.ius
# 禁用=base,updates源,并通过ius源安装git
yum --disablerepo=base,updates --enablerepo=ius install git
或者通过源码编译安装
#安装依赖
yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
yum install gcc perl-ExtUtils-MakeMaker
# 删除旧版本git
yum remove git
# 下载源码
cd /usr/src
wget https://www.kernel.org/pub/software/scm/git/git-2.0.4.tar.gz
tar xzf git-2.0.4.tar.gz
# 编译安装
cd git-2.0.4
make prefix=/usr/local/git all
make prefix=/usr/local/git install
#修改环境变量
echo 'export PATH=$PATH:/usr/local/git/bin' >> /etc/bashrc
#或者这种方式修改环境变量
echo 'export PATH=$PATH:/usr/local/git/bin' > /etc/profile.d/git.sh
source /etc/bashrc
# 验证
git --version
git version 2.0.4
https://stackoverflow.com/questions/21820715/how-to-install-latest-version-of-git-on-centos-8-x-7-x-6-x
https://blog.k4nz.com/afa4776b30b16636f860bd76316370ac/
https://ius.io/setup
https://itsfoss.com/install-git-ubuntu/