Centos7升級Git版本

centos 升級 Git 版本

問題描述

centos7 系統默認的 git 安裝版本是 1.8,但是在項目構建中發現 git 版本過低,於是用源碼編譯的方式進行升級.同時該文章也適用於安裝新的 git,相信大家對 git 都有一定的瞭解了,在文章過程中有的步驟也就不細細講了.

操作環境

centos7.0

軟件準備

git 版本,libiconv

安裝流程

1、第一步卸載原有的 git。

yum remove git

2、安裝相關依賴

yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel asciidoc
yum install  gcc perl-ExtUtils-MakeMaker

3、安裝 git

將壓縮包解壓到/usr/local/src目錄
tar -C /usr/local/src -vxf git-2.7.3.tar.xz
cd git-2.7.3
// 編譯
make prefix=/usr/local/git all
// 安裝
make prefix=/usr/local/git install
// 寫入到環境變量中(方法一)
echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/profile && source /etc/profile
// 寫入到環境變量中(方法二)
export PATH=$PATH:/usr/local/bin/git
// 查看是否已經安裝成功
git --version
問題解決

正常的流程就是按照上面的流程進行安裝即可,下面總結一些在安裝過程中遇到的幾個問題.
1、make prefix=/usr/local/git all 進行編譯的時候提示如下錯誤

 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

這個問題主要是系統缺少 libiconv 庫導致的。根據上面提供的鏈接,下載 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
建立軟連接
ln -s /usr/local/lib/libiconv.so /usr/lib
ln -s /usr/local/lib/libiconv.so.2 /usr/lib

這時候還 libiconv 庫已經安裝完成,下面進入我們的 git 安裝目錄,按照下面的方式進行安裝

make configure
./configure --prefix=/usr/local --with-iconv=/usr/local/libiconv
編譯
make
安裝
make install
加入環境變量
export PATH=$PATH:/usr/local/bin/git
檢測版本號
git --version

2、在安裝 libiconv 時會遇到./stdio.h:1010:1: error: 'gets' undeclared here (not in a function)的錯誤提示,進行下面的操作即可解決.

進入錯誤文件路徑
cd 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
本文由博客一文多發平臺 OpenWrite 發佈!
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章