安装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");
替换为:
#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服务器安装的,所有步骤都以列出,如有问题请联系