Linux下编译安装 Git

439人浏览 / 0人评论

Linux下编译安装 Git

标签(空格分隔): Linux
#安装 Git 是时候动手尝试下 Git 了,不过得先安装好它。有许多种安装方式,主要分为两种,一种是通过编译源代码来安装;另一种是使用为特定平台预编译好的安装包。 ##从源代码安装 若是条件允许,从源代码安装有很多好处,至少可以安装最新的版本。Git 的每个版本都在不断尝试改进用户体验,所以能通过源代码自己编译安装最新版本就再好不过了。有些 Linux 版本自带的安装包更新起来并不及时,所以除非你在用最新的 distro 或者 backports,那么从源代码安装其实该算是最佳选择。
Git 的工作需要调用 curl,zlib,openssl,expat,libiconv 等库的代码,所以需要先安装这些依赖工具。在有 yum 的系统上(比如 Fedora)或者有 apt-get 的系统上(比如 Debian 体系),可以用下面的命令安装:
$ yum install curl-devel expat-devel gettext-devel \
  openssl-devel zlib-devel

$ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \
  libz-dev libssl-dev
之后,从下面的 Git 官方站点下载最新版本源代码:
https://www.kernel.org/pub/software/scm/git/
提供一个2.12.2的版本下载地址
https://www.kernel.org/pub/software/scm/git/git-2.12.2.tar.gz
然后编译并安装:
$ tar -zxf git-2.12.2.tar.gz
$ cd git-2.12.2
$ make prefix=/usr/local all
$ sudo make prefix=/usr/local install
##安装错误解决方案 安装过程可能会出现以下错误
LINK git-credential-store
libgit.a(utf8.o): In function `reencode_string_iconv’:
/opt/git-master/utf8.c:530: undefined reference to `libiconv’
libgit.a(utf8.o): In function `reencode_string_len’:
/opt/git-master/utf8.c:569: undefined reference to `libiconv_open’
/opt/git-master/utf8.c:588: undefined reference to `libiconv_close’
/opt/git-master/utf8.c:582: undefined reference to `libiconv_open’
collect2: ld 返回 1
make: *** [git-credential-store] 错误 1
解决办法:
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  && sudo  make install
然后返回git重新编译
cd ../git-2.12.2
make configure
./configure --prefix=/usr/local -with-iconv=/usr/local/libiconv
make
这个时候又出现错误了
/usr/bin/perl Makefile.PL PREFIX='/usr/local' INSTALL_BASE='' --localedir='/usr/local/share/locale'
Can't locate ExtUtils/MakeMaker.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at Makefile.PL line 3.
BEGIN failed--compilation aborted at Makefile.PL line 3.
make[1]: *** [perl.mak] Error 2
make: *** [perl/perl.mak] Error 2
这次我们用 yum 一键安装
yum install perl-ExtUtils-Embed -y
继续编译
make configure
./configure --prefix=/usr/local -with-iconv=/usr/local/libiconv
make
make install 
就OK了 现在已经可以用 git 命令了,用 gitGit 项目仓库克隆到本地,以便日后随时更新:
$ git clone git://git.kernel.org/pub/scm/git/git.git