centos7 安装Git
安裝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
編譯時出現如下異常:
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
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在此編譯安裝
cd ../git-2.3.0 make cleanautoconf./configure --prefix=/usr/local --with-iconv=/usr/local/libiconv/ make install
錯誤如下:
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 1make[2]: Leaving directory `/usr/local/src/zabbix-2.4.7/libiconv-1.14/srclib'make[1]: *** [all] Error 2make[1]: Leaving directory `/usr/local/src/zabbix-2.4.7/libiconv-1.14/srclib'make: *** [all] Error 2
?
解決辦法:
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服務器安裝的,所有步驟都以列出,如有問題請聯系
總結
以上是生活随笔為你收集整理的centos7 安装Git的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python的redis数据库连接与使用
- 下一篇: VIM配置攻略(最强干货加强版)