讓curl支持http2(Ubuntu 16.04.4 LTS)

1. Ubuntu16.04倉庫中的curl是7.47.0,默認不支持http2。linux

apt-cache policy curl

curl:
  Installed: (none)
  Candidate: 7.47.0-1ubuntu2.8
  Version table:
     7.47.0-1ubuntu2.8 500
        500 http://mirrors.163.com/ubuntu xenial-security/main amd64 Packages
        500 http://mirrors.163.com/ubuntu xenial-updates/main amd64 Packages
     7.47.0-1ubuntu2 500
        500 http://mirrors.163.com/ubuntu xenial/main amd64 Packages
lsb_release -a

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.4 LTS
Release:        16.04
Codename:       xenial

2. 能夠從源碼安裝curl。ubuntu

sudo apt-get install build-essential nghttp2 libnghttp2-dev libssl-dev
wget https://curl.haxx.se/download/curl-7.58.0.tar.gz
tar -xvf curl-7.58.0.tar.gz
cd curl-7.58.0
./configure --with-nghttp2 --prefix=/usr/local --with-ssl=/usr/local/ssl
make
sudo make install
sudo ldconfig

源碼安裝到了/usr/local/bin/curl,倉庫安裝的curl在/usr/bin/curl,卸載倉庫安裝的curl。bash

sudo apt-get purge curl

查看是否支持http2。curl

curl --version

curl 7.58.0 (x86_64-pc-linux-gnu) libcurl/7.58.0 OpenSSL/1.0.2g zlib/1.2.8 nghttp2/1.7.1
Release-Date: 2018-01-24
Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets HTTPS-proxy

3. 測試http2。測試

curl -I --http2 https://http2.akamai.com/

...
GET / HTTP/2

HTTP/2 200
server: Apache
...

OK.ui

引用:https://askubuntu.com/questions/884899/how-do-i-install-curl-with-http2-supporturl

相關文章
相關標籤/搜索