想要从源代码构建最新的 cURL?
操作系统附带的 cURL 可能不是最新的,如果您需要最新版本来满足特定要求,那么您需要从源代码构建。
最近,我在 CentOS 上使用 cURL 和默认发布的版本测试 HTTP/3,但这没有用。 顺便说一句,你可以用 cURL 做更多的事情。
[[email protected] ~]# 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 tftp Features: AsynchDNS GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL libz unix-sockets [[email protected] ~]#
但是,最新的 cURL 版本 (7.67) 支持 HTTP/3。 所以,我只有一个选择——从源代码构建。 这只是一个例子; 您可能还有其他一些要求。
以下示例适用于 CentOS 8.x 和 Ubuntu 20.x 上的 7.67(我写的最新版本)。 但是对于任何其他版本,该过程保持不变。
目录
先决条件
让我们安装所需的依赖项。
- 更新系统。 虽然这是可选的,但我更喜欢这样做。 我总是有最新的安装包。
yum update -y
- 安装所需的包
yum install wget gcc openssl-devel -y
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。
喜欢阅读这篇文章吗? 与世界分享如何?