准备工作:
CentOS 上的最新 git 版本也只有 1.8.3, 就想试着装上最新的版本, 没想到差点玩脱, 全当记录一次冒险经历
Development tools 没装的要装上, 不然 GCC 编译时会出错
# yum -y groupinstall Development tools
GCC 用于编译安装包
# yum install gcc perl-ExtUtils-MakeMaker
再卸载 CentOS 自带的老版本 git
# yum -y remove git
下载 git 并安装
- # cd /usr/src
- # wget https://www.kernel.org/pub/software/scm/git/git-2.16.2.tar.gz
- # tar -zxvf git-2.16.2.tar.gz
安装注意事项:
- # cd git-2.16.2
- # make prefix=/usr/local/git all
此时报错
/usr/src/git-2.12.0/utf8.c:463: 对 libiconv 未定义的引用
libgit.a(utf8.o): 在函数 reencode_string_len 中:
/usr/src/git-2.12.0/utf8.c:524: 对 libiconv_open 未定义的引用
/usr/src/git-2.12.0/utf8.c:535: 对 libiconv_close 未定义的引用
/usr/src/git-2.12.0/utf8.c:529: 对 libiconv_open 未定义的引用
collect2: 错误: ld 返回 1
make: *** [git-credential-store] 错误 1
原方案:
- # make prefix=/usr/local/git all
- # make prefix=/usr/local/git install
解决方案:
可替换为
- # ./configure --without-iconv
- # make CFLAGS=-liconv prefix=/usr/local/git all
- # make CFLAGS=-liconv prefix=/usr/local/git install
最后将 git 加入环境变量
- # echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc
- # source /etc/bashrc
大功告成! 查看一下 git 的版本
- # git --version
- >> git version 2.16.2
来源: http://www.bubuko.com/infodetail-2508050.html