我用了通常的:

yum install git

它没有在我的CentOS 6上安装最新版本的git。如何更新到CentOS 6的最新版本?该解决方案适用于CentOS 7等更新版本的CentOS。


当前回答

我个人倾向于在安装非标准软件和替换分布式组件时为CentOS构建rpm包。为此,我建议您使用Mock来创建一个干净的构建环境。

程序如下:

Obtain the source RPMS or a suitable SPEC file and pristine source tarball. In this case one may find source RPM packages for git2X for CentOS-6 at: http://dl.iuscommunity.org/pub/ius/archive/CentOS/6/SRPMS/. Packages for other CentOS releases are also available. Install the necessary support software: yum install epel-release # you need this for mock yum install rpm-build yum install redhat-rpm-config yum install rpmdevtools yum install mock Add a rpm build user account (do not build as root or as a real user - security issues will come back to bite you). sudo adduser builder --home-dir /home/builder \ --create-home --user-group --groups mock \ --shell /bin/bash --comment "rpm package builder" Next we need a build environment. su -l builder rpmdev-setuptree This produces the following directory structure: ~ └── rpmbuild ├── BUILD ├── RPMS ├── SOURCES ├── SPECS └── SRPMS We are using a prepared SRPMS so the SOURCES tarballs can be ignored for this case and we can go direct to SRPMS. wget http://dl.iuscommunity.org/pub/ius/archive/CentOS/6/SRPMS/git2u-2.5.3-1.ius.centos6.src.rpm \ -O ~/rpmbuild/SRPMS/git2u-2.5.3-1.ius.centos6.src.rpm Configure mock (as root) cd /etc/mock rm default.cfg ln -s epel-6-x86_64.cfg default.cfg vim default.cfg Disable the beta repos. Enable the base and update repos. Initialize the build tree (/var/lib/mock is default) mock --init If we were building from SOURCES then this is where we would employ the SPEC file and use mock --buildsrpm . . .. But in this case we go directly to the binary build step: mock --no-clean --rebuild ~/rpmbuild/SRPMS/git2u-2.5.3-1.ius.centos6.src.rpm This will resolve the build dependencies and download them (about 95 or so packages) into the clean build root. It will then extract the sources and build the binary from the provided SRPM and leave it in /var/lib/mock/epel-6-x86_64/result; or in whatever custom build root location and architecture you provided. It will take a long time. There is a lot to this package; particularly documentation. If all goes well then you should end up with a suit of RPM packages suitable for installation in place of the distro version. This is what I ended up with: ll /var/lib/mock/epel-6-x86_64/result total 34996 -rw-rw-r--. 1 byrnejb mock 448455 Oct 30 10:09 build.log -rw-rw-r--. 1 byrnejb mock 52464 Oct 30 10:09 emacs-git2u-2.5.3-1.ius.el6.noarch.rpm -rw-rw-r--. 1 byrnejb mock 47228 Oct 30 10:09 emacs-git2u-el-2.5.3-1.ius.el6.noarch.rpm -rw-rw-r--. 1 byrnejb mock 8474478 Oct 30 09:57 git2u-2.5.3-1.ius.el6.src.rpm -rw-rw-r--. 1 byrnejb mock 8877584 Oct 30 10:09 git2u-2.5.3-1.ius.el6.x86_64.rpm -rw-rw-r--. 1 byrnejb mock 27284 Oct 30 10:09 git2u-all-2.5.3-1.ius.el6.noarch.rpm -rw-rw-r--. 1 byrnejb mock 27800 Oct 30 10:09 git2u-bzr-2.5.3-1.ius.el6.noarch.rpm -rw-rw-r--. 1 byrnejb mock 112564 Oct 30 10:09 git2u-cvs-2.5.3-1.ius.el6.noarch.rpm -rw-rw-r--. 1 byrnejb mock 436176 Oct 30 10:09 git2u-daemon-2.5.3-1.ius.el6.x86_64.rpm -rw-rw-r--. 1 byrnejb mock 15858600 Oct 30 10:09 git2u-debuginfo-2.5.3-1.ius.el6.x86_64.rpm -rw-rw-r--. 1 byrnejb mock 60556 Oct 30 10:09 git2u-email-2.5.3-1.ius.el6.noarch.rpm -rw-rw-r--. 1 byrnejb mock 274888 Oct 30 10:09 git2u-gui-2.5.3-1.ius.el6.noarch.rpm -rw-rw-r--. 1 byrnejb mock 79176 Oct 30 10:09 git2u-p4-2.5.3-1.ius.el6.noarch.rpm -rw-rw-r--. 1 byrnejb mock 483132 Oct 30 10:09 git2u-svn-2.5.3-1.ius.el6.x86_64.rpm -rw-rw-r--. 1 byrnejb mock 173732 Oct 30 10:09 gitk2u-2.5.3-1.ius.el6.noarch.rpm -rw-rw-r--. 1 byrnejb mock 115692 Oct 30 10:09 gitweb2u-2.5.3-1.ius.el6.noarch.rpm -rw-rw-r--. 1 byrnejb mock 57196 Oct 30 10:09 perl-Git2u-2.5.3-1.ius.el6.noarch.rpm -rw-rw-r--. 1 byrnejb mock 89900 Oct 30 10:09 perl-Git2u-SVN-2.5.3-1.ius.el6.noarch.rpm -rw-rw-r--. 1 byrnejb mock 101026 Oct 30 10:09 root.log -rw-rw-r--. 1 byrnejb mock 980 Oct 30 10:09 state.log Install using yum or rpm. You will require git2u-2.5.3-1.ius.el6.x86_64.rpm at a minimum and such additional support packages as it requires (perl-Git2u-2.5.3-1.ius.el6.noarch.rpm) or you desire. This build has a cyclic dependency: git2u-2.5.3-1.ius.el6.x86_64.rpm depends upon perl-Git2u-2.5.3-1.ius.el6.noarch.rpm and perl-Git2u-2.5.3-1.ius.el6.noarch.rpm depends upon git2u-2.5.3-1.ius.el6.x86_64.rpm. A straight install with rpm will thus fail. There are two ways of dealing with it: Install both at the same time via yum: yum localinstall \ git2u-2.5.3-1.ius.el6.x86_64.rpm \ perl-Git2u-2.5.3-1.ius.el6.noarch.rpm` Setup a local yum repo. I am including my LocalFile.repo file below as it contains instructions on how to do this and provides the necessary repo file at the same time.

cat /etc/yum.repos.d/LocalFile.repo
# LocalFile.repo
#
#  This repo is used with a local filesystem repo.
#
# To use this repo place the rpm package in /root/RPMS/yum.repo/Packages.
# Then run: createrepo --database --update /root/RPMS/yum.repo.
#
# To use:
#  yum --enablerepo=localfile [command]
#  
# or to use only ONLY this repo, do this:
#
#  yum --disablerepo=\* --enablerepo=localfile [command]

[localfile]
baseurl=file:///root/RPMS/yum.repo
name=CentOS-$releasever - Local Filesystem repo

# Before persistently enabling this repo see the priority note below.
enabled=0
gpgcheck=0

# When this repo is enabled all packages in repos with priority>5
# will not be updated even when they have a more recent version.
# Be careful with this.
priority=5

您还可能需要手动预安装其他依赖包,例如从通常的存储库中获得的perl-TermReadKey。

其他回答

这个指南奏效了:

# hostnamectl
  Operating System: CentOS Linux 7 (Core)
# git --version
git version 1.8.3.1
# sudo yum remove git*
# sudo yum -y install https://packages.endpointdev.com/rhel/7/os/x86_64/endpoint-repo.x86_64.rpm
# sudo yum install git
# git --version
git version 2.24.1

您可以使用WANDisco的CentOS存储库来安装Git 2。x: CentOS 6, CentOS 7

安装WANDisco回购包: 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 http://opensource.wandisco.com/centos/7/git/x86_64/wandisco-git-release-7-2.noarch.rpm 安装最新版本的Git 2.x: Yum安装git 验证已安装Git的版本: git -版本

截至2020年3月2日,WANDisco的最新可用版本为2.22.0。

下面是我在centos 6上安装git的方法。

sudo yum groupinstall "Development Tools"
sudo yum install zlib-devel perl-ExtUtils-MakeMaker asciidoc xmlto openssl-devel curl-devel
sudo yum install wget
cd ~
wget -O git.zip https://github.com/git/git/archive/v2.7.2.zip
unzip git.zip
cd git-2.7.2
make configure
./configure --prefix=/usr/local
make all doc
sudo make install install-doc install-html

看了一下博客,我在其中一条评论中找到了解决方案。确保你把rpmforge存储库添加到CentOS yum中,然后运行下面的命令:

yum --disablerepo=base,updates --enablerepo=rpmforge-extras install git

如果你已经安装了git,那么使用:

yum --disablerepo=base,updates --enablerepo=rpmforge-extras update git

相关的问题:

在CentOS 6.4上升级git到最新版本时遇到问题

请注意更新:

感谢Anthony Hatzopoulos,对于git v1.8x,你需要使用git18:

yum --disablerepo=base,updates --enablerepo=rpmforge-extras install git18 

说明更新2:

也感谢@Axlrod的以下提示和@Hiphip的反馈:

更改rpmforge。回购文件有rpmforge-extras启用, Yum更新git。否则它会抱怨依赖问题。

说明更新3:

安装特定版本的git,比如2.x 我找到了这个简单易用的指南,教你如何下载GIT源代码并自行编译(并安装)。如果接受的答案没有给你想要的版本,请尝试以下说明:

http://tecadmin.net/install-git-2-0-on-centos-rhel-fedora/

(并从上面的源代码中粘贴/重新格式化,以防稍后被删除)

步骤1:安装所需软件包

首先,我们需要确保在您的系统上安装了所需的软件包。在编译Git源代码之前,使用以下命令安装所需的包。

# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
# yum install  gcc perl-ExtUtils-MakeMaker

步骤2:卸载旧的Git RPM

现在删除之前通过RPM文件或Yum包管理器安装的Git。如果您的旧版本也是通过源代码编译的,则跳过此步骤。

# yum remove git

步骤3:下载并编译Git源代码

从内核git下载git源代码,或者直接使用以下命令下载git 2.0.4。

# 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

下载并提取Git源代码后,使用以下命令编译源代码。

# 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
#  or
# echo 'export PATH=$PATH:/usr/local/git/bin' > /etc/profile.d/git.sh
#
# source /etc/bashrc

HINT 1: Updated method of adding compiled git bin directory to bashrc. Because echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc used "" instead of '', it would expand the current session's value for $PATH instead of keeping it as a variable, and could adversely affect the entire system. At the minimum, it should use '' instead of "" and should really be a separate script in /etc/profile.d/ HINT 2 (@DJB): /usr/local/git/bin before $PATH, since the older version of git was already on $PATH: export PATH=/usr/local/git/bin:$PATH

步骤4。查看Git版本

完成上述步骤后,您就成功地在系统中安装了Git。让我们使用以下命令来检查git版本

# git --version

git version 2.0.4

我还想补充一点,GIT网站上的“入门”指南也包括如何自己下载和编译的说明:

http://git-scm.com/book/en/v2/Getting-Started-Installing-Git

我找到了这个简单易用的指南,教你如何下载GIT源代码并自行编译(并安装)。如果接受的答案没有给你想要的版本,请尝试以下说明:

http://tecadmin.net/install-git-2-0-on-centos-rhel-fedora/

(并从上面的源代码中粘贴/重新格式化,以防稍后被删除)

步骤1:安装所需软件包

首先,我们需要确保在您的系统上安装了所需的软件包。在编译Git源代码之前,使用以下命令安装所需的包。

# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
# yum install  gcc perl-ExtUtils-MakeMaker

步骤2:卸载旧的Git RPM

现在删除之前通过RPM文件或Yum包管理器安装的Git。如果您的旧版本也是通过源代码编译的,则跳过此步骤。

# yum remove git

步骤3:下载并编译Git源代码

从内核git下载git源代码,或者直接使用以下命令下载git 2.5.3。

# cd /usr/src
# wget https://www.kernel.org/pub/software/scm/git/git-2.5.3.tar.gz
# tar xzf git-2.5.3.tar.gz

下载并提取Git源代码后,使用以下命令编译源代码。

# cd git-2.5.3
# make prefix=/usr/local/git all
# make prefix=/usr/local/git install
# echo 'pathmunge /usr/local/git/bin/' > /etc/profile.d/git.sh 
# chmod +x /etc/profile.d/git.sh
# source /etc/bashrc

步骤4。查看Git版本

完成上述步骤后,您已经成功地在系统中安装了Git。使用以下命令查看git版本

# git --version

git version 2.5.3

我还想补充一点,GIT网站上的“入门”指南也包括如何自己下载和编译的说明:

http://git-scm.com/book/en/v2/Getting-Started-Installing-Git