linux git升级安装以及报错问题解决方法

本文详细介绍如何在Linux环境下从零开始安装Git版本控制系统,包括安装编译依赖、卸载旧版、下载与编译安装Git,以及解决编译过程中遇到的libiconv链接错误问题。同时,提供环境变量配置和Git版本检查的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


参考网址:

https://www.jianshu.com/p/512d25c9df10
https://blog.youkuaiyun.com/liuchenxia8/article/details/79652847
https://blog.youkuaiyun.com/qq_28903377/article/details/86148687
https://blog.youkuaiyun.com/daojibruce/article/details/75315401
https://www.cnblogs.com/gxldan/p/4069956.html

安装git

一、先安装编译时依赖的包

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

二、卸载旧版本

yum remove git

三、下载与安装

cd ~
wget https://www.kernel.org/pub/software/scm/git/git-2.15.1.tar.xz
tar -vxf git-2.15.1.tar.xz
cd git-2.15.1
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
git --version

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

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

二、创建一个软链接到/usr/lib

ln -s /usr/local/lib/libiconv.so /usr/lib
ln -s /usr/local/lib/libiconv.so.2 /usr/lib

三、回到git目录继续编译

cd ~/git-2.15.1(我放在家目录)
make configure
./configure --prefix=/usr/local --with-iconv=/usr/local/libiconv
make
make install

四、编辑环境变量配置(给到所有用户): vim /etc/profile

1 export PATH=$PATH:/usr/local/git/bin  或者 echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc (需要退出 root 用户再操作. 否则就只有root用户内部才生效了)  
2 刷新配置:source /etc/bashrc

五、查看GIT版本

git --version  
git version 2.15.1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值