如何在 CENTOS 5.5上安装 git?

如何在 CENTOS 5.5机器上安装 git? 我试图从百胜餐厅安装,但得到了下面的消息。

root@host [~]# sudo yum install git
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* addons: centos.mirrors.tds.net
* base: mirror.ubiquityservers.com
* extras: mirrors.serveraxis.net
* updates: pubmirrors.reflected.net
addons                                                   |  951 B     00:00
base                                                     | 2.1 kB     00:00
extras                                                   | 2.1 kB     00:00
updates                                                  | 1.9 kB     00:00
Excluding Packages in global exclude list
Finished
Setting up Install Process
No package git available.
Nothing to do
root@host [~]#
104708 次浏览

从源头?回购协议上的?最简单的方法是使用回购协议: sudo yum install git应该这样做。如果主回购协议没有提供 git,那么可能首先需要建立一个额外的回购协议,比如 EPEL

如果要从源代码安装,可以尝试使用 这些指令。如果你已经安装了 yum-utils,那么实际上也会比这更简单。 * * :

sudo yum build-dep git
wget http://kernel.org/pub/software/scm/git/<latest-git-source>.tar.gz
tar -xvjf <latest-git>.tar.gz
cd <git>
make (possibly a ./configure before this)
sudo make install

* * 用您需要的路径替换 <>中包含的部分。确切的过程可能略有不同,因为我没有亲自从源代码编译 git (例如,可能有一个配置脚本)。如果你不知道我在说什么,那么你可能只需要按照我的第一个建议从回购安装。

好吧,还有更多的东西,你需要 zlib。Zlib 是 CentOS 的一部分,但是您需要开发表单来获得 zlib.h... 注意,zlib 开发的 yum 名称 可能与 ubuntu/debian 上的 apt-get 有很大的不同,下面的内容实际上是可行的 用我的 CentOS 版本
特别是在 git 上执行./configure,然后尝试 make,第一次构建失败,遗漏了 zlib.h

我用了两个步骤来解决这个问题 A)我的 CentOS 版本得到了 RPMFORGE

参见: Www.centos.org/modules/newbb/viewtopic.php?topic_id=18506&forum=38 还有这个: Wiki.centos.org/additionalresources/repositories/rpmforge

在我的情况下[作为 root 或使用 sudo ]

$ wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
$ rpm -K rpmforge-release-0.5.2-2.el5.rf.*.rpm
$ rpm -i rpmforge-release-0.5.2-2.el5.rf.*.rpm
## Note: the RPM for rpmforge is small (like 12.3K) but don't let that fool
## you; it augments yum the next time you use yum
## [this is the name that YUM found] (still root or sudo)
$ yum install zlib-devel.x86_64
## and finally in the source directory for git (still root or sudo):
$ ./configure (this worked before, but I ran it again to be sure)
$ make
$ make install

(这次安装把它默认放在 /usr/local/bin/git... 不是我最喜欢的选择,但默认情况下没问题) ... git 工作得很好!

如果您正在使用 CentOS,内置的 yum存储库似乎没有包含 git,因此,您将需要向系统添加一个额外的存储库。对于我的服务器,我发现 网络存储库似乎是最新的,然后 git的安装如下:

# Add the repository
rpm -Uvh http://repo.webtatic.com/yum/centos/5/latest.rpm


# Install the latest version of git
yum install --enablerepo=webtatic git-all

解决 Missing Dependency: perl(Git)错误:

yum install --enablerepo=webtatic --disableexcludes=main  git-all

我已经尝试了几个方法从这个问题,他们都失败了我的 CentOs,要么是因为错误的回购或丢失的文件。

下面是我使用的方法(安装版本1.7.8时) :

    yum -y install zlib-devel openssl-devel cpio expat-devel gettext-devel
wget http://git-core.googlecode.com/files/git-1.7.8.tar.gz
tar -xzvf ./git-1.7.8.tar.gz
cd ./git-1.7.8
./configure
make
make install

你可能想从这里下载一个不同的版本: Http://code.google.com/p/git-core/downloads/list

这对我在 CentOS 上很有用:

  1. 安装依赖项:

    yum -y install zlib-devel openssl-devel cpio expat-devel gettext-devel
    
  2. Get Git

    cd /usr/local/src
    wget http://code.google.com/p/git-core/downloads/detail?name=git-1.7.8.3.tar.gz
    tar xvzf git-1.7.8.3.tar.gz
    cd git-1.7.8.3
    
  3. Build Git

    ./configure
    make
    make install
    

只要:

sudo rpm -Uvh https://archives.fedoraproject.org/pub/archive/epel/5/i386/epel-release-5-4.noarch.rpm
sudo yum install git-core
yum -y install zlib-devel openssl-devel cpio expat-devel gettext-devel gcc
wget http://git-core.googlecode.com/files/git-1.7.11.4.tar.gz
tar zxvf git-1.7.11.4.tar.gz
cd git-1.7.11.4
./configure
make
make install

安装 git

  1. 安装最后一次释放

Rpm-Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm

  1. 从存储库安装 git

Yum install git

编辑 /etc/yum.repos.d/Centos*,使所有具有 enabled = 0的行都具有 enabled = 1

我敢肯定,这个问题即将死亡,现在 RHEL 5已接近生命的尽头,但答案似乎已经变得简单得多了:

sudo yum install epel-release
sudo yum install git

为我新安装的 CentOS 5.11工作。

看起来 CentOS 5的回购协议正在消失。这个问题中提到的大多数 Git 都不再联机,似乎没有 Git,或者有一个非常老的 Git 版本。下面是我用来从源代码构建 OpenSSL、 IDN2、 PCRE、 cURL 和 Git 的脚本。git://https://协议都可用于克隆。

随着时间的推移,档案的名称将需要更新。例如,在撰写本文时,openssl-1.0.2k.tar.gz是1.0.2系列中最新的一个。

戴尔安德森的答案使用 RHEL 回购看起来不错的时刻,但它是一个相当老的版本。Red Hat 提供了 Git 版本1.8,而下面的脚本从源代码构建了2.12。


#!/usr/bin/env bash


# OpenSSL installs into lib64/, while cURL installs into lib/
INSTALL_ROOT=/usr/local
INSTALL_LIB32="$INSTALL_ROOT/lib"
INSTALL_LIB64="$INSTALL_ROOT/lib64"


OPENSSL_TAR=openssl-1.0.2k.tar.gz
OPENSSL_DIR=openssl-1.0.2k


ZLIB_TAR=zlib-1.2.11.tar.gz
ZLIB_DIR=zlib-1.2.11


UNISTR_TAR=libunistring-0.9.7.tar.gz
UNISTR_DIR=libunistring-0.9.7


IDN2_TAR=libidn2-0.16.tar.gz
IDN2_DIR=libidn2-0.16


PCRE_TAR=pcre2-10.23.tar.gz
PCRE_DIR=pcre2-10.23


CURL_TAR=curl-7.53.1.tar.gz
CURL_DIR=curl-7.53.1


GIT_TAR=v2.12.2.tar.gz
GIT_DIR=git-2.12.2


###############################################################################


# I don't like doing this, but...
read -s -p "Please enter password for sudo: " SUDO_PASSWWORD


###############################################################################


echo
echo "********** zLib **********"


wget "http://www.zlib.net/$ZLIB_TAR" -O "$ZLIB_TAR"


if [[ "$?" -ne "0" ]]; then
echo "Failed to download zLib"
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi


rm -rf "$ZLIB_DIR" &>/dev/null
tar -xzf "$ZLIB_TAR"
cd "$ZLIB_DIR"


LIBS="-ldl -lpthread" ./configure --enable-shared --libdir="$INSTALL_LIB64"


if [[ "$?" -ne "0" ]]; then
echo "Failed to configure zLib"
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi


make -j 4


if [ "$?" -ne "0" ]; then
echo "Failed to build zLib"
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi


echo "$SUDO_PASSWWORD" | sudo -S make install


cd ..


###############################################################################


echo
echo "********** Unistring **********"


# https://savannah.gnu.org/bugs/?func=detailitem&item_id=26786
wget "https://ftp.gnu.org/gnu/libunistring/$UNISTR_TAR" --no-check-certificate -O "$UNISTR_TAR"


if [[ "$?" -ne "0" ]]; then
echo "Failed to download IDN"
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi


rm -rf "$UNISTR_DIR" &>/dev/null
tar -xzf "$UNISTR_TAR"
cd "$UNISTR_DIR"


LIBS="-ldl -lpthread" ./configure --enable-shared --libdir="$INSTALL_LIB64"


if [[ "$?" -ne "0" ]]; then
echo "Failed to configure IDN"
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi


make -j 4


if [ "$?" -ne "0" ]; then
echo "Failed to build IDN"
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi


echo "$SUDO_PASSWWORD" | sudo -S make install


cd ..


###############################################################################


echo
echo "********** IDN **********"


# https://savannah.gnu.org/bugs/?func=detailitem&item_id=26786
wget "https://alpha.gnu.org/gnu/libidn/$IDN2_TAR" --no-check-certificate -O "$IDN2_TAR"


if [[ "$?" -ne "0" ]]; then
echo "Failed to download IDN"
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi


rm -rf "$IDN2_DIR" &>/dev/null
tar -xzf "$IDN2_TAR"
cd "$IDN2_DIR"


LIBS="-ldl -lpthread" ./configure --enable-shared --libdir="$INSTALL_LIB64"


if [[ "$?" -ne "0" ]]; then
echo "Failed to configure IDN"
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi


make -j 4


if [ "$?" -ne "0" ]; then
echo "Failed to build IDN"
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi


echo "$SUDO_PASSWWORD" | sudo -S make install


cd ..


###############################################################################


echo
echo "********** OpenSSL **********"


wget "https://www.openssl.org/source/$OPENSSL_TAR" -O "$OPENSSL_TAR"


if [[ "$?" -ne "0" ]]; then
echo "Failed to download OpenSSL"
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi


rm -rf "$OPENSSL_DIR" &>/dev/null
tar -xzf "$OPENSSL_TAR"
cd "$OPENSSL_DIR"


# OpenSSL and enable-ec_nistp_64_gcc_12 option
IS_X86_64=$(uname -m 2>&1 | egrep -i -c "(amd64|x86_64)")


CONFIG=./config
CONFIG_FLAGS=(no-ssl2 no-ssl3 no-comp shared "-Wl,-rpath,$INSTALL_LIB64" --prefix="$INSTALL_ROOT" --openssldir="$INSTALL_ROOT")
if [[ "$IS_X86_64" -eq "1" ]]; then
CONFIG_FLAGS+=("enable-ec_nistp_64_gcc_128")
fi


"$CONFIG" "${CONFIG_FLAGS[@]}"


if [[ "$?" -ne "0" ]]; then
echo "Failed to configure OpenSSL"
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi


make depend
make -j 4


if [ "$?" -ne "0" ]; then
echo "Failed to build OpenSSL"
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi


echo "$SUDO_PASSWWORD" | sudo -S make install_sw


cd ..


###############################################################################


echo
echo "********** PCRE **********"


# https://savannah.gnu.org/bugs/?func=detailitem&item_id=26786
wget "https://ftp.pcre.org/pub/pcre//$PCRE_TAR" --no-check-certificate -O "$PCRE_TAR"


if [[ "$?" -ne "0" ]]; then
echo "Failed to download PCRE"
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi


rm -rf "$PCRE_DIR" &>/dev/null
tar -xzf "$PCRE_TAR"
cd "$PCRE_DIR"


make configure
CPPFLAGS="-I$INSTALL_ROOT/include" LDFLAGS="-Wl,-rpath,$INSTALL_LIB64 -L$INSTALL_LIB64" \
LIBS="-lidn2 -lz -ldl -lpthread" ./configure --enable-shared --enable-pcre2-8 --enable-pcre2-16 --enable-pcre2-32 \
--enable-unicode-properties --enable-pcregrep-libz --prefix="$INSTALL_ROOT" --libdir="$INSTALL_LIB64"


if [[ "$?" -ne "0" ]]; then
echo "Failed to configure PCRE"
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi


make all -j 4


if [ "$?" -ne "0" ]; then
echo "Failed to build PCRE"
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi


echo "$SUDO_PASSWWORD" | sudo -S make install


cd ..


###############################################################################


echo
echo "********** cURL **********"


# https://savannah.gnu.org/bugs/?func=detailitem&item_id=26786
wget "https://curl.haxx.se/download/$CURL_TAR" --no-check-certificate -O "$CURL_TAR"


if [[ "$?" -ne "0" ]]; then
echo "Failed to download cURL"
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi


rm -rf "$CURL_DIR" &>/dev/null
tar -xzf "$CURL_TAR"
cd "$CURL_DIR"


CPPFLAGS="-I$INSTALL_ROOT/include" LDFLAGS="-Wl,-rpath,$INSTALL_LIB64 -L$INSTALL_LIB64" \
LIBS="-lidn2 -lssl -lcrypto -lz -ldl -lpthread" \
./configure --enable-shared --with-ssl="$INSTALL_ROOT" --with-libidn2="$INSTALL_ROOT" --libdir="$INSTALL_LIB64"


if [[ "$?" -ne "0" ]]; then
echo "Failed to configure cURL"
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi


make -j 4


if [ "$?" -ne "0" ]; then
echo "Failed to build cURL"
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi


echo "$SUDO_PASSWWORD" | sudo -S make install


cd ..


###############################################################################


echo
echo "********** Git **********"


wget "https://github.com/git/git/archive/$GIT_TAR" -O "$GIT_TAR"


if [[ "$?" -ne "0" ]]; then
echo "Failed to download Git"
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi


rm -rf "$GIT_DIR" &>/dev/null
tar -xzf "$GIT_TAR"
cd "$GIT_DIR"


make configure
CPPFLAGS="-I$INSTALL_ROOT/include" LDFLAGS="-Wl,-rpath,$INSTALL_LIB64,-rpath,$INSTALL_LIB32 -L$INSTALL_LIB64 -L$INSTALL_LIB32" \
LIBS="-lidn2 -lssl -lcrypto -lz -ldl -lpthread" ./configure --with-openssl --with-curl --with-libpcre --prefix="$INSTALL_ROOT"


if [[ "$?" -ne "0" ]]; then
echo "Failed to configure Git"
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi


make all -j 4


if [ "$?" -ne "0" ]; then
echo "Failed to build Git"
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi


MAKE=make
MAKE_FLAGS=(install)
if [[ ! -z `which asciidoc 2>/dev/null | grep -v 'no asciidoc'` ]]; then
if [[ ! -z `which xmlto 2>/dev/null | grep -v 'no xmlto'` ]]; then
MAKE_FLAGS+=("install-doc" "install-html" "install-info")
fi
fi


echo "$SUDO_PASSWWORD" | sudo -S "$MAKE" "${MAKE_FLAGS[@]}"


cd ..


###############################################################################


echo
echo "********** Cleanup **********"


rm -rf "$OPENSSL_TAR  $OPENSSL_DIR  $UNISTR_TAR  $UNISTR_DIR  $CURL_TAR  $CURL_DIR"
rm -rf "$PCRE_TAR $PCRE_DIR $ZLIB_TAR $ZLIB_DIR $IDN2_TAR $IDN2_DIR $GIT_TAR $GIT_DIR"


[[ "$0" = "$BASH_SOURCE" ]] && exit 0 || return 0

随着 CentOS 5到达 EOL,EPEL 的 URL 也发生了变化,仅仅是为2017年及以后更新一下:

sudo rpm -Uvh http://archives.fedoraproject.org/pub/archive/epel/5/x86_64/epel-release-5-4.noarch.rpm
sudo yum install git

这个能让你得到1.8分2.3分

yum -y install zlib-devel openssl-devel cpio expat-devel gettext-devel


Get the required version of GIT from https://www.kernel.org/pub/software/scm/git/


wget https://www.kernel.org/pub/software/scm/git/{version.gz}


tar -xzvf git-version.gz


cd git-version


./configure


make


make install

使用以下说明安装了 git:

  1. 安装 EPELV5
    #rpm -Uvh http://archives.fedoraproject.org/pub/archive/epel/5/x86_64/epel-release-5-4.noarch.rpm

  2. 安装 Git
    # yum install git git-daemon

  3. 将军
    # git --version
    git version 1.8.2.3

  4. 可选地安装 Git GUI
    # yum install git-gui

对于 i386,在步骤 # 1的 URL 中用 i386替换 x86 _ 64。

#rpm -Uvh http://archives.fedoraproject.org/pub/archive/epel/5/i386/epel-release-5-4.noarch.rpm