前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >centos7 安装Git

centos7 安装Git

作者头像
Lansonli
发布2021-10-09 10:37:41
5190
发布2021-10-09 10:37:41
举报
文章被收录于专栏:Lansonli技术博客

安装git前先检查一下是否有旧版本git

通过git –version查看系统带的版本,如果有就删除

# yum remove git

1.安装依赖的包

yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel yum install  gcc perl-ExtUtils-MakeMaker 2.下载git源码并解压

wget https://github.com/git/git/archive/v2.3.0.zip unzip v2.3.0.zip(或:unzip v2.3.0) 进入解压的目录

cd git-2.3.0 3.编译安装

安装在/usr/local/下

make prefix=/usr/local/git all make prefix=/usr/local/git install

 编译时出现如下异常:

代码语言:javascript
复制
libgit.a(utf8.o): In function `reencode_string_iconv':
/root/git-2.3.0/utf8.c:463: undefined reference to `libiconv'
libgit.a(utf8.o): In function `reencode_string_len':
/root/git-2.3.0/utf8.c:502: undefined reference to `libiconv_open'
/root/git-2.3.0/utf8.c:521: undefined reference to `libiconv_close'
/root/git-2.3.0/utf8.c:515: undefined reference to `libiconv_open'
collect2: ld 返回 1
make: *** [git-credential-store] 错误 1

  下载并安装libiconv

代码语言:javascript
复制
cd ..
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar -zxvf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv  &&  make  && make install

  返回git在此编译安装

代码语言:javascript
复制
cd ../git-2.3.0
make clean
autoconf
./configure --prefix=/usr/local --with-iconv=/usr/local/libiconv/
make install

错误如下:

代码语言:javascript
复制
    In file included from progname.c:26:0:
    ./stdio.h:1010:1: error: ‘gets’ undeclared here (not in a function)
    _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
    ^
    make[2]: *** [progname.o] Error 1
    make[2]: Leaving directory `/usr/local/src/zabbix-2.4.7/libiconv-1.14/srclib'
    make[1]: *** [all] Error 2
    make[1]: Leaving directory `/usr/local/src/zabbix-2.4.7/libiconv-1.14/srclib'
    make: *** [all] Error 2

解决办法:

代码语言:javascript
复制
vi libiconv-1.14/srclib/stdio.in.h

将698行的代码:_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");替换为:

代码语言:javascript
复制
#if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16)
 _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");#endif

此时执行git --version仍然提示command not found,git已经安装成功,可能是配有配置环境变量

4.配置环境变量

vim /etc/profile 在文件最后一行添加:export PATH=/usr/local/git/bin:$PATH,保存退出

发现仍然不行,这是因为配置还未生效,不重启系统,使用source命令立即生效

source /etc/profile 然后git --version,提示 git version 2.3.0,已安装成功。

我这是用一个新linux服务器安装的,所有步骤都以列出,如有问题请联系

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/05/06 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档