How to use curl command with http/2 on MacOS X

I am using a MacOS sierra (version 10.12.1). How do I use curl command with http2/ protocol? I am getting an error that read as follows:


            curl -I --http2
            curl: (1) Unsupported protocol

How do I solve this problem and use cURL with HTTP/2 on Mac OS X or MacOS Sierra?

The default version of curl does not support HTTP/2. Here is my current version on MacOS sierra:
$ curl --version
curl 7.49.1 (x86_64-apple-darwin16.0) libcurl/7.49.1 SecureTransport zlib/1.2.8
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz UnixSockets

So if I try to pass the --http2 option to curl command, I will get the following error on screen:
$ curl -I --http2
curl: (1) Unsupported protocol

Fixing curl: (1) Unsupported protocol error on MacOS

Use the brew command as follows to install curl with nghttp2. nghttp2 is an implementation of HTTP/2 and its header compression algorithm HPACK in C. You need to compile and install cURL as follows:
$ brew update
$ brew upgrade
$ brew install curl --with-nghttp2

Sample outputs:

Fig.01: Fixing curl: (1) Unsupported protocol on Mac OS X

Fixing curl: (1) Unsupported protocol on Mac OS X

Please note down the path “/usr/local/Cellar/curl/7.50.3/bin/curl”

Create a shortlink in your ~/bin/

Type the following command:
$ mkdir $HOME/bin/
$ cd ~/bin/
$ ln -s /usr/local/Cellar/curl/7.50.3/bin/curl
$ ~/bin/curl --version

Sample outputs:

curl 7.50.3 (x86_64-apple-darwin16.1.0) libcurl/7.50.3 OpenSSL/1.0.2j zlib/1.2.8 nghttp2/1.16.0
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp 
Features: IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets 

How do I test it?

Pass the --http2 flag to http2 enabled site:
$ ~/bin/curl -I --http2
Sample outputs:

HTTP/2 200 
server: nginx
date: Tue, 01 Nov 2016 21:59:18 GMT
content-type: text/html;charset=utf-8
vary: Accept-Encoding
cache-control: public,max-age=900,s-maxage=900,must-revalidate
expires: Tue, 01 Nov 2016 22:03:40 GMT
etag: de8af9a212f436d9d4d45f4cc994b2ca
last-modified: Mon, 05 Sep 2016 07:49:45 GMT
front-end-https: on
strict-transport-security: max-age=15768000
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-xss-protection: 1

A note about replacing the MacOS curl with updated version

You can create a softlink to the formula to replace the system cURL with PATH magic,
$ brew link curl --force
$ curl --version

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

1 comment… add one
  • Dave Nov 2, 2016 @ 18:53

    The macOS Sierra 10.12.1 curl has some additional features that you’ll lose if you build –with-nghttp2. The missing ones are: AsynchDNS, GSS-API, Kerberos, and SPNEGO (as listed in the ‘curl –version’ output). To get HTTP/2 and the missing features too, use:

    $ brew install curl --with-nghttp2 --with-gssapi --with-c-ares

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.