Install Curl with HTTP2 support on Ubuntu (BASH)

Although the version of curl in the Ubuntu repos is sufficiently recent to support HTTP/2, Ubuntu have compiled the packages without nghttp2 support, so if you try and use --http2 you'll probably receive the output curl: (1) Unsupported protocol

This snippet details how to install deps, and then compile curl with http/2 support - it can then be installed alongside, or over the top of the existing curl (alongside is better IMO).

Details

  • Language: BASH

Snippet

sudo apt-get nghttp2 libnghttp2-dev libssl-dev
wget https://curl.haxx.se/download/curl-7.66.0.tar.gz
tar xzf curl-7.66.0.tar.gz
cd curl-7.66.0/
./configure --with-nghttp2 --with-ssl
make

# If you want to install alongside, and only for you
echo "alias curl-h2=\"$PWD/src/curl --http2 --http2-prior-knowledge\"" >> ~/.bashrc

# Or, alongside but for everyone
echo "alias curl-h2=\"$PWD/src/curl --http2 --http2-prior-knowledge\"" | sudo tee -a /etc/profile

# Or to install over the top 
# (will install as curl and you will need to specify --http2 --http2-prior-knowledge )
sudo make install

Usage Example

# Assuming an alias was created
curl-h2 "https://www.bentasker.co.uk" -v -o/dev/null

# If not, then
curl --http2 --http2-prior-knowledge "https://www.bentasker.co.uk" -v -o/dev/null