想要从源代码构建现代 cURL?
您的操作系统附带的 cURL 可能不是最新的,因此如果您需要最新版本来满足您的特定要求,您应该从源代码构建它。
我最近在 CentOS 上的默认发布版本上使用 cURL 测试 HTTP/3,但它不起作用。顺便说一句,您还可以使用 cURL 做更多事情。
[root@lab ~]# curl --version
curl 7.29.0 (x86_64-redhat-linux-gnu) libcurl/7.29.0 NSS/3.44 zlib/1.2.7 libidn/1.28 libssh2/1.8.0
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smtp smtps telnet <a href="https://.com/tftp-servers-for-windows/">tftp</a>
Features: AsynchDNS GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL libz unix-sockets
[root@lab ~]#但是,最新的 cURL 版本 (7.67) 支持 HTTP/3。因此从源代码构建是唯一的选择。这只是一个例子。可能还有一些其他要求。
以下示例来自 CentOS 8.x 和 Ubuntu 20.x 上的 7.67(撰写本文时最新)。但是,其他版本的步骤是相同的。

先决条件
让我们安装所需的依赖项。
- 更新您的系统。这是可选的,但我更喜欢这样做。始终安装最新的软件包。
yum update -y- 安装所需的包
yum install wget gcc openssl-devel -y- 下载最新的 cURL 源。要查看最新版本,请访问官方下载页面。
wget https://curl.haxx.se/download/curl-7.67.0.tar.gz- 解压下载的
gz文件。
gunzip -c curl-7.67.0.tar.gz | tar xvf -将在您当前的工作目录中创建一个新文件夹

在 CentOS/RHEL 上构建 cURL
下载并提取最新的 cURL 后,就可以构建它了。
- 解压后进入新建的文件夹
cd curl-7.67.0- 配置 SSL 如下
./configure --with-ssl- 您将看到类似于以下内容的输出:
configure: Configured to build curl/libcurl:
Host setup: x86_64-pc-linux-gnu
Install prefix: /usr/local
Compiler: gcc
CFLAGS: -Werror-implicit-function-declaration -O2 -Wno-system-headers -pthread
CPPFLAGS:
LDFLAGS:
LIBS: -lssl -lcrypto -lssl -lcrypto -lz
curl version: 7.67.0
SSL: enabled (OpenSSL)
SSH: no (--with-libssh2)
zlib: enabled
brotli: no (--with-brotli)
GSS-API: no (--with-gssapi)
TLS-SRP: no (--enable-tls-srp)
resolver: POSIX threaded
IPv6: enabled
Unix sockets: enabled
IDN: no (--with-{libidn2,winidn})
Build libcurl: Shared=yes, Static=yes
Built-in manual: enabled
--libcurl option: enabled (--disable-libcurl-option)
Verbose errors: enabled (--disable-verbose)
Code coverage: disabled
SSPI: no (--enable-sspi)
ca cert bundle: /etc/pki/tls/certs/ca-bundle.crt
ca cert path: no
ca fallback: no
LDAP: no (--enable-ldap / --with-ldap-lib / --with-lber-lib)
LDAPS: no (--enable-ldaps)
RTSP: enabled
RTMP: no (--with-librtmp)
Metalink: no (--with-libmetalink)
PSL: no (libpsl not found)
Alt-svc: no (--enable-alt-svc)
HTTP2: disabled (--with-nghttp2)
HTTP3: disabled (--with-ngtcp2, --with-quiche)
ESNI: no (--enable-esni)
Protocols: DICT FILE FTP FTPS GOPHER HTTP HTTPS IMAP IMAPS POP3 POP3S RTSP SMB SMBS SMTP SMTPS TELNET TFTP
Features: SSL IPv6 UnixSockets libz AsynchDNS NTLM NTLM_WB HTTPS-proxy- 让我们安装吧
make
make install需要几秒钟才能完成,完成后,您可以检查版本以确认安装成功。

在 Ubuntu 上构建 cURL
假设您已下载先决条件部分中提到的最新版本。
- 导航到解压下载的 cURL 的文件夹
- 安装依赖项
apt-get install -y binutils-common binutils make- 如果没有安装上述依赖项(binutils),可能会遇到以下错误:
configure: error: ar not found in PATH. Cannot continue without ar.- 然后使用
configure命令构建它。
./configure --with-ssl- 如果上述执行没有错误,则使用make命令安装。
make
make install就是这样!

确认
使用--version查看版本详细信息。
# curl --version
curl 7.67.0 (x86_64-pc-linux-gnu) libcurl/7.67.0 OpenSSL/1.0.2k-fips zlib/1.2.7
Release-Date: 2019-11-06
Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: AsynchDNS HTTPS-proxy IPv6 Largefile libz NTLM NTLM_WB SSL UnixSockets
#结论
知道步骤后就很容易了。我希望这可以帮助您从源代码安装 cURL。




![2021 年如何设置 Raspberry Pi Web 服务器 [指南]](https://i0.wp.com/pcmanabu.com/wp-content/uploads/2019/10/web-server-02-309x198.png?w=1200&resize=1200,0&ssl=1)

