CentOS7中升级Curl

先情提要

在部署 php7.4 的时候,发现 make 错误,翻看日志提示 curl 版本不支持几个函数,原来是机器部署的 curl 版本过低 curl 7.54.1_2017 (x86_64-pc-linux-gnu)
遂开始着手升级至最新 8.0.30

实施过程

先看看目前curl 版本,是否可以使用
yum update curl
因为部分第三方云已经把内核替换成自家(华为云与火山引擎)不行,则需要自己手工更新
1、首先安装 epel-release
yum -y install epel-release

2、下载并安装 curl 的 rpm 包
wget http://mirror.city-fan.org/ftp/contrib/yum-repo/rhel7/x86_64/city-fan.org-release-3-8.rhel7.noarch.rpm
rpm -ivh city-fan.org-release-2-2.rhel7.noarch.rpm

3、将[city-fan.org]的 enable 值修改为 1
vim /etc/yum.repos.d/city-fan.org.repo

1
2
3
4
5
6
7
[city-fan.org]
name=city-fan.org repository for Red Hat Enterprise Linux (and clones) $releasever ($basearch)
#baseurl=http://mirror.city-fan.org/ftp/contrib/yum-repo/rhel$releasever/$basearch
mirrorlist=http://mirror.city-fan.org/ftp/contrib/yum-repo/mirrorlist-rhel$releasever
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-city-fan.org

4、更新 curl
yum update curl --enablerepo=city-fan.org -y

5、安装完成,检查版本,完成升级
curl -V

6、同时移除 city-fan.org.repo 并删除
cp /etc/yum.repos.d/city-fan.org.repo /etc/yum.repos.d/city-fan_bak.org.repo -a

如果此方法不能正常升级,请确认系统是否安装了多个 curl
which curl
whereis curl
如果无法确认,可以选择编译安装,然后重新系统指向

1
2
3
4
5
6
7
wget https://curl.haxx.se/download/curl-7.76.1.tar.gz
tar -xvf curl-7.76.1.tar.gz
cd ./curl-7.76.1
./buildconf
./configure --with-ssl=/opt/openssl --with-nghttp2=/usr/local --disable-file --without-pic --disable-shared
make
sudo make install

重新指向
echo "export PATH=/usr/local/curl/bin:$PATH" >> /etc/profile
刷新系统变量
source /etc/profile
再次查询 curl 版本
curl --version

curl 7.76.1 (x86_64-unknown-linux-gnu) libcurl/7.76.1 OpenSSL/1.1.1w zlib/1.2.7
Release-Date: 2021-04-14
Protocols: dict file ftp ftps gopher gophers http https imap imaps mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS HTTPS-proxy IPv6 Largefile libz NTLM NTLM_WB SSL TLS-SRP UnixSocket

这里需要注意的是 curl 的版本号是否和 libcurl 一样,不一样则去浏览
vim /etc/ld.so.conf
资源库是否正确软连接

1
2
include /etc/ld.so.conf.d/*.conf
/usr/local/lib # 正确的curl的资源应该在此软连接到安装目录,64位系统为lib64

更改完毕记得刷新配置文件
sudo ldconfig -v
sudo ldconfig
同时注意有无出现 WARNING

记录问题

Q: curl: symbol lookup error: curl: undefined symbol: curl_mime_free
Q: curl: symbol lookup error: curl: undefined symbol: curl_url_cleanup
Q: curl: symbol lookup error: curl: undefined symbol: curl_url
这类问题是 libcurl 软连接缺失,建议先去确认/usr/local/lib 等地方的 libcurl.so 文件是否链接到正确的地方。

1
2
3
4
5
6
sudo ldconfig -v
# ***
#/usr/local/lib:
# libcurl.so.4 -> libcurl.so.4.4.0
# libpcre.so.1 -> libpcre.so.1.2.10
# 打个比方这里的libcurl就是错误链接了,理应是/usr/local/curl/lib/libcurl.so.4.7.0
作者

Catooilg

发布于

2023-05-20

更新于

2023-10-15

许可协议

评论