CentOS 7 安装新版 git
从第三方仓库安装
-
添加 Wandisco 库:
sudo vim /etc/yum.repos.d/git.repo[wandisco-git] name=Wandisco GIT Repository baseurl=http://opensource.wandisco.com/centos/7/git/$basearch/ enabled=1 gpgcheck=1 gpgkey=http://opensource.wandisco.com/RPM-GPG-KEY-WANdiscosudo rpm --import http://opensource.wandisco.com/RPM-GPG-KEY-WANdisco -
安装 git:
sudo yum install git截至 2025-04-10,Wandisco 库提供的最新 git 版本是
2.41.0。
参考:How to install Git on CentOS 7 | Globo.Tech
手动编译
-
安装依赖:
sudo yum install -y dh-autoreconf libcurl-devel expat-devel gettext-devel openssl-devel perl-devel zlib-devel如果需要安装不同格式的文档(doc, html, info),需要安装如下包:
sudo yum install -y asciidoc xmlto docbook2X util-linuxsudo ln -s /usr/bin/db2x_docbook2texi /usr/bin/docbook2x-texi -
进入 www.kernel.org 下载 git 源码压缩包。
wget https://www.kernel.org/pub/software/scm/git/git-2.49.0.tar.xz tar -xJf git-*.tar.xz && rm git-*.tar.xz cd git-* -
编译并安装:
make configure ./configure --prefix=$HOME/.local make all doc info -j$(nproc) make install install-doc install-html install-info
Troubleshooting
‘CURLOPT_PROXYHEADER’ undeclared
In file included from /usr/include/curl/curl.h:2251:0,
from git-curl-compat.h:3,
from http.c:4:
http.c: In function ‘set_proxyauth_name_password’:
http.c:655:28: error: ‘CURLOPT_PROXYHEADER’ undeclared (first use in this function)
curl_easy_setopt(result, CURLOPT_PROXYHEADER,
^
http.c:655:28: note: each undeclared identifier is reported only once for each function it appears in
make: *** [http.o] Error 1
这个错误表明编译器找不到 CURLOPT_PROXYHEADER 这个宏。CURLOPT_PROXYHEADER 是 libcurl 7.37.0 及之后版本中引入的。如果你的系统上的 libcurl 的版本低于此版本,就会出现这个错误。
检查当前 libcurl 版本:
curl --version
如果 libcurl 版本低于 7.37.0,则需要升级。CentOS 7 官方支持的最新版本只有 curl 7.29.0,因此我们需要从源码编译安装最新版的 libcurl。
-
安装依赖
libpsl:sudo yum install epel-release # 安装 EPEL 仓库 sudo yum install libpsl libpsl-devel # 安装 libpsl -
前往 curl.se 下载源码压缩包。
wget https://curl.se/download/curl-8.13.0.tar.xz tar -xJf curl-*.tar.xz && rm curl-*.tar.xz cd curl-*EPEL(Extra Packages for Enterprise Linux)仓库为 CentOS 提供了许多额外的软件包,其中包含 libpsl。
-
解压并进入源码包,编译并安装:
mkdir build && cd build ../configure --with-openssl --prefix="$HOME/.local" make -j$(nproc) make install -
设置
PKG_CONFIG_PATH和LD_LIBRARY_PATH以确保编译器和链接器使用我们编译的libcurl版本:export PKG_CONFIG_PATH="$HOME/.local/lib/pkgconfig" export LD_LIBRARY_PATH="$HOME/.local/lib"
storage size of ‘tz’ isn’t known
t/unit-tests/clar/clar.c: In function ‘clar_time_now’:
t/unit-tests/clar/clar.c:274:18: error: storage size of ‘tz’ isn’t known
struct timezone tz;
^
这个问题是我在编译 git-2.47.0 时遇到的,当时并没有解决。不过通过降低 git 版本可以解决这个问题。我成功编译并安装的版本为 git-2.26.2。
undefined reference to `libiconv'
/bin/ld: libgit.a(utf8.o): in function `reencode_string_iconv':
/src/git-2.49.0/utf8.c:500: undefined reference to `libiconv'
/bin/ld: libgit.a(utf8.o): in function `reencode_string_len':
/src/git-2.49.0/utf8.c:595: undefined reference to `libiconv_open'
/bin/ld: /src/git-2.49.0/utf8.c:605: undefined reference to `libiconv_close'
/bin/ld: /src/git-2.49.0/utf8.c:595: undefined reference to `libiconv_open'
/bin/ld: /src/git-2.49.0/utf8.c:605: undefined reference to `libiconv_close'
/bin/ld: /src/git-2.49.0/utf8.c:600: undefined reference to `libiconv_open'
collect2: error: ld returned 1 exit status
make: *** [Makefile:2883: git-daemon] Error 1
根据 issue Build failed due to undefined reference to libiconv,猜测可能是环境污染的问题。在创建新用户后成功编译:
sudo useradd -m builder
sudo su -l builder
asciidoc evaluation error
asciidoc: WARNING: git-show.adoc: line 81: {eval:re.sub(r'(<[-a-zA-Z0-9.]+>)', r'<emphasis>\1</emphasis>', re.sub(r'([\[\s|()>]|^|\]|>)(\.?([-a-zA-Z0-9:+=~@,\/_^\$]+\.?)+)',r'\1<literal>\2</literal>', re.sub(r'(\.\.\.?)([^\]$.])', r'<literal>\1</literal>\2', macros.passthroughs[int(attrs['passtext'][1:-1])] if attrs['passtext'][1:-1].isnumeric() else attrs['passtext'][1:-1])))}: evaluation error
WARNING,不用管。
@item missing argument
user-manual.texi:419: warning: @item missing argument
WARNING,不用管。

浙公网安备 33010602011771号