在CentOS5,由于yum源中没有git,所以需要预先安装一系列的依赖包。但在CentOS6的yum源中已经有git的版本了,可以直接使用yum源进行安装
sudo yum install git
但是yum源中安装的git版本是1.7.1,太老了,Github等需要的Git版本最低都不能低于1.7.2 。所以我们一般不用上面的方法。而是下载git源码,编译安装。
编译安装的步骤是:
(1)首先先更新系统
sudo yum update
(2)安装依赖的包
sudo yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker
(3)下载git源码并解压缩
wget https://github.com/git/git/archive/v2.3.0.zip
unzip v2.3.0.zip
cd git-2.3.0
(4)编译安装
cd /usr/local/scr/git-2.8.3
make configure
./configure --prefix=/usr/local --with-iconv=/usr/local/libiconv
make
make install
注:安装git 2.x遇到undefined reference to `libiconv’
LINK git-credential-store
libgit.a(utf8.o): In function `reencode_string_iconv':
/usr/src/git-2.8.3/utf8.c:463: undefined reference to `libiconv'
libgit.a(utf8.o): In function `reencode_string_len':
/usr/src/git-2.8.3/utf8.c:502: undefined reference to `libiconv_open'
/usr/src/git-2.8.3/utf8.c:521: undefined reference to `libiconv_close'
/usr/src/git-2.8.3/utf8.c:515: undefined reference to `libiconv_open'
collect2: ld returned 1 exit status
make: *** [git-credential-store] Error 1
解决如下:
1、安装libiconv
cd /usr/local/src
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
2、创建一个软链接到/usr/lib
ln -s /usr/local/lib/libiconv.so /usr/lib
ln -s /usr/local/lib/libiconv.so.2 /usr/lib
3、重新编译后,发现还是同样的错误undefined reference to `libiconv'
相关资料参考:debian centos 等linux系统编译报错 undefined reference to `libiconv'-无忧答案网
# 将iconv.h重新命名
mv /usr/local/include/iconv.h /usr/local/include/iconv.h.bak
4、然后回到git目录继续编译
cd /usr/local/scr/git-2.8.3
make configure
./configure --prefix=/usr/local --with-iconv=/usr/local/libiconv
make
make install
(5)检查一下版本号
git --version
参考文献
CentOS6.6下安装git 2.6.2_Roda的博客的博客-优快云博客
安装git 2.x遇到undefined reference to `libiconv‘_单林敏的博客-优快云博客
debian centos 等linux系统编译报错 undefined reference to `libiconv'-无忧答案网