如何在 Redhat 6.x/7.x 中安装最新版本的 git

How to install latest version of git in Redhat 6.x/7.x

我正在尝试在 Redhat6 中安装 git。 我正在关注 how to install git 本教程。

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

# cd git-2.0.5
# make prefix=/usr/local/git all
# make prefix=/usr/local/git install
# echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc
# source /etc/bashrc

# git --version

我能够克隆存储库并能够下载 git zip 文件。 但是当我执行这个命令时。

 make prefix=/usr/local/git all

我收到这个错误

[varun@home git-2.0.5]# make prefix=/usr/local/git all 
GIT_VERSION =2.0.5
* new build flags
CC credential-store.o /bin/sh: cc: 
command not found make: *** [credential-store.o] Error 127

我该如何解决?

我可以使用 yum install git 安装 git。但默认情况下 1.7.1 正在安装。但是我想安装上面2.

编辑 1 当我执行

yum groupinstall 'Development Tools'

它下载了所需的依赖项,上面的错误消失了。

现在当我执行此 make prefix=/usr/local/git all 时出现以下错误

    CC bulk-checkin.o
In file included from cache.h:4,
                 from bulk-checkin.h:7,
                 from bulk-checkin.c:4:
git-compat-util.h:213:25: warning: openssl/ssl.h: No such file or directory
git-compat-util.h:214:25: warning: openssl/err.h: No such file or directory
git-compat-util.h:320:25: warning: openssl/evp.h: No such file or directory
git-compat-util.h:321:26: warning: openssl/hmac.h: No such file or directory
git-compat-util.h:323:28: warning: openssl/x509v3.h: No such file or directory
In file included from bulk-checkin.h:7,
                 from bulk-checkin.c:4:
cache.h:11:21: warning: openssl/sha.h: No such file or directory
In file included from bulk-checkin.c:5:
csum-file.h:11: error: expected specifier-qualifier-list before ‘SHA_CTX’
csum-file.h:23: error: expected specifier-qualifier-list before ‘SHA_CTX’
bulk-checkin.c:96: error: expected declaration specifiers or ‘...’ before ‘SHA_CTX’
bulk-checkin.c: In function ‘stream_to_pack’:
bulk-checkin.c:128: warning: implicit declaration of function ‘SHA1_Update’
bulk-checkin.c:128: error: ‘ctx’ undeclared (first use in this function)
bulk-checkin.c:128: error: (Each undeclared identifier is reported only once
bulk-checkin.c:128: error: for each function it appears in.)
bulk-checkin.c: In function ‘deflate_to_pack’:
bulk-checkin.c:193: error: ‘SHA_CTX’ undeclared (first use in this function)
bulk-checkin.c:193: error: expected ‘;’ before ‘ctx’
bulk-checkin.c:205: warning: implicit declaration of function ‘SHA1_Init’
bulk-checkin.c:205: error: ‘ctx’ undeclared (first use in this function)
bulk-checkin.c:222: warning: passing argument 3 of ‘stream_to_pack’ makes integer from pointer without a cast
bulk-checkin.c:95: note: expected ‘int’ but argument is of type ‘off_t *’
bulk-checkin.c:222: error: incompatible type for argument 6 of ‘stream_to_pack’
bulk-checkin.c:95: note: expected ‘const char *’ but argument is of type ‘enum object_type’
bulk-checkin.c:222: warning: passing argument 7 of ‘stream_to_pack’ makes integer from pointer without a cast
bulk-checkin.c:95: note: expected ‘unsigned int’ but argument is of type ‘const char *’
bulk-checkin.c:222: error: too many arguments to function ‘stream_to_pack’
bulk-checkin.c:237: warning: implicit declaration of function ‘SHA1_Final’
make: *** [bulk-checkin.o] Error 1

make prefix=/usr/local/git install 我明白了

    CC bulk-checkin.o
In file included from cache.h:4,
                 from bulk-checkin.h:7,
                 from bulk-checkin.c:4:
git-compat-util.h:213:25: warning: openssl/ssl.h: No such file or directory
git-compat-util.h:214:25: warning: openssl/err.h: No such file or directory
git-compat-util.h:320:25: warning: openssl/evp.h: No such file or directory
git-compat-util.h:321:26: warning: openssl/hmac.h: No such file or directory
git-compat-util.h:323:28: warning: openssl/x509v3.h: No such file or directory
In file included from bulk-checkin.h:7,
                 from bulk-checkin.c:4:
cache.h:11:21: warning: openssl/sha.h: No such file or directory
In file included from bulk-checkin.c:5:
csum-file.h:11: error: expected specifier-qualifier-list before ‘SHA_CTX’
csum-file.h:23: error: expected specifier-qualifier-list before ‘SHA_CTX’
bulk-checkin.c:96: error: expected declaration specifiers or ‘...’ before ‘SHA_CTX’
bulk-checkin.c: In function ‘stream_to_pack’:
bulk-checkin.c:128: warning: implicit declaration of function ‘SHA1_Update’
bulk-checkin.c:128: error: ‘ctx’ undeclared (first use in this function)
bulk-checkin.c:128: error: (Each undeclared identifier is reported only once
bulk-checkin.c:128: error: for each function it appears in.)
bulk-checkin.c: In function ‘deflate_to_pack’:
bulk-checkin.c:193: error: ‘SHA_CTX’ undeclared (first use in this function)
bulk-checkin.c:193: error: expected ‘;’ before ‘ctx’
bulk-checkin.c:205: warning: implicit declaration of function ‘SHA1_Init’
bulk-checkin.c:205: error: ‘ctx’ undeclared (first use in this function)
bulk-checkin.c:222: warning: passing argument 3 of ‘stream_to_pack’ makes integer from pointer without a cast
bulk-checkin.c:95: note: expected ‘int’ but argument is of type ‘off_t *’
bulk-checkin.c:222: error: incompatible type for argument 6 of ‘stream_to_pack’
bulk-checkin.c:95: note: expected ‘const char *’ but argument is of type ‘enum object_type’
bulk-checkin.c:222: warning: passing argument 7 of ‘stream_to_pack’ makes integer from pointer without a cast
bulk-checkin.c:95: note: expected ‘unsigned int’ but argument is of type ‘const char *’
bulk-checkin.c:222: error: too many arguments to function ‘stream_to_pack’
bulk-checkin.c:237: warning: implicit declaration of function ‘SHA1_Final’
make: *** [bulk-checkin.o] Error 1

还有这两行

 # echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc
 # source /etc/bashrc

执行成功

但是当我输入 git --version 时,我仍然得到

bash: /usr/bin/git: No such file or directory

看起来 /bin/sh: cc: command not found 是错误消息,它被分成两行以增加额外的混乱。即没有 cc 命令。

说明需要安装C编译器。如果您 运行 以下命令,它应该安装所有必要的工具(gcc、binutils 等)来编译 git。

yum groupinstall 'Development Tools'

您还缺少必要的开发头文件,例如 openssl:

yum install openssl-devel curl-devel expat-devel gettext-devel zlib-devel

请在下面找到我在系统上没有互联网访问权限的情况下安装 Git 所遵循的步骤

  • 在您的 PC/Laptop https://www.kernel.org/pub/software/scm/git/ 上从下方 link 下载所需的 tarball。我使用了 Git-2.8,因为客户要求版本 >=2.7.4
  • 连接到远程 Linux 系统(通过 winscp 或其他远程连接工具)。并且 Place/Move 下载的 git-[version].tar.gz 文件位于 linux 系统上您要安装“git”的所需位置。我把它放在目录中:/var/opt/teradata/packages/Package/GIT/
  • 从命令提示转到放置上述文件的目录,然后 运行 在命令下方解压包 tar -xvzf git-2.8.0.tar.gz
  • cd到上面untar命令新建的目录,例如cd git-2.8.0/.
  • 使用 ls -ltr 确认所有需要的文件和目录都已解压缩到上述文件夹中。
  • 使用以下命令设置路径和前缀变量。

    PATH=$PATH:/var/opt/teradata/packages/Package/GIT/git-2.8.0/usr/bin
    PATH=$PATH:/var/opt/teradata/packages/Package/GIT/git-2.8.0
    export PATH=$PATH:/var/opt/teradata/packages/Package/GIT/git-2.8.0
    make prefix=/usr/local/git all
    echo $CC
    
  • 运行 ./configure 检查预安装配置检查。
  • 运行 make install 安装。
  • 检查 git 是否已正确安装 git --version