How to Use cURL HTTP/2 on macOS
cURL is one of most powerful tools for testing HTTP traffic. We typically use cURL to interact with HTTP APIs or test websites.
Although cURL supports HTTP/2, the version that’s installed on macOS Sierra does not. Read Update.
If you try to use the --http2 flag, you’ll receive the following error:
$ curl -I --http2 https://www.itnota.com |
curl: (1) Unsupported protocol |
Fortunately, we can use another installation from Homebrew alongside the default version. To do so, just type the following command in the Terminal window (assuming you already have Homebrew installed):
$ brew install curl —with-nghttp2 |
That’s it.
Keep in mind that this installation does not replace the default curl in the system and this can be a good or bad thing for you.
If you want to keep things separately, you’re done as you can always call the 2nd curl by typing its full path:
$ /usr/local/opt/curl/bin/curl -I --http2 https://www.itnota.com |
If you check the version of the two in this example:
# Default Version |
$ curl --version |
curl 7.51.0 (x86_64-apple-darwin16.0) libcurl/7.51.0 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 |
# Homebrew Version |
$ /usr/local/opt/curl/bin/curl --version |
curl 7.54.0 (x86_64-apple-darwin16.6.0) libcurl/7.54.0 OpenSSL/1.0.2l zlib/1.2.8 nghttp2/1.23.1 |
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 HTTPS-proxy |
If you want to set the curl you installed from Homebrew as the default, keep reading.
Set Homebrew cURL as the Default
There are several ways to set the new version as your default curl, but I believe the best and safest way to do it was already suggested at the end of installation process.
Notice that after installing the curl from Homebrew you’ll see a warning and instruction. If you missed it, it will look similar to this:

[...] |
######################################################################## 100.0% |
==> ./configure --disable-silent-rules --prefix=/usr/local/Cellar/curl/7.54.0 --with-==> make install==> |
Caveats |
This formula is keg-only, which means it was not symlinked into /usr/local, |
because macOS already provides this software and installing another version in |
parallel can cause all kinds of trouble. |
If you need to have this software first in your PATH run: |
echo 'export PATH="/usr/local/opt/curl/bin:$PATH"' >> ~/.bash_profile |
For compilers to find this software you may need to set: |
LDFLAGS: -L/usr/local/opt/curl/lib |
CPPFLAGS: -I/usr/local/opt/curl/include |
For pkg-config to find this software you may need to set: |
PKG_CONFIG_PATH: /usr/local/opt/curl/lib/pkgconfig |
[...] |
Just following the instruction provided, type in the following:
$ echo 'export PATH="/usr/local/opt/curl/bin:$PATH"' >> ~/.bash_profile |
You need to restart terminal and this time if you call curl without the full path, it will run the Homebrew version.
If you need to refer back to the default macOS version, just edit your ~/.bash_profile file by typing the following command:
$ sudo nano ~/.bash_profile |
Look for this line:
export PATH="/usr/local/opt/curl/bin:$PATH" |
and comment it out like so:
# export PATH="/usr/local/opt/curl/bin:$PATH" |
And press CTRL-X and Yes to exit and save it.
Now you can test it using —http2 flag:
$ curl -I --http2 https://www.itnota.com |
Update
Update on 5/21/2019: There are two updates that render this post obsolete.
First update is that the version of curl installed on macOS now supports HTTP/2.
The second update is that Homebrew has removed the –with-nghttp2 option from curl which makes the instructions not accurate.
You can still follow the instructions above for Homebrew version of curl only if you substitute it with the curl-openssl and its corresponding path instead.
So you can uninstall Homebrew curl by running the following:
$ brew uninstall curl |
Then install curl-openssl by running the following:
$ brew install curl-openssl |
That’s it. You don’t even need to specify any flag such as --with-nghttp2 on the curl-openssl install. It will just work. You just need to pay attention to the path where the curl is installed. It is
/usr/local/opt/curl-openssl/bin/curl |
The latest comparison between the two versions of curl:
# Default Version |
$ curl --version |
curl 7.54.0 (x86_64-apple-darwin18.0) libcurl/7.54.0 LibreSSL/2.6.5 zlib/1.2.11 nghttp2/1.24.1 |
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 HTTP2 UnixSockets HTTPS-proxy |
# Homebrew Version |
$ /usr/local/opt/curl-openssl/bin/curl --version |
curl 7.65.0 (x86_64-apple-darwin18.6.0) libcurl/7.65.0 OpenSSL/1.0.2r zlib/1.2.11 brotli/1.0.7 c-ares/1.15.0 libssh2/1.8.2 nghttp2/1.38.0 librtmp/2.3 |
Release-Date: 2019-05-22 |
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp |
Features: AsynchDNS brotli GSS-API HTTP2 HTTPS-proxy IPv6 Kerberos Largefile libz Metalink NTLM NTLM_WB SPNEGO SSL TLS-SRP UnixSockets |
Further Reading
brew install curl –with-nghttp2 errors saying “invalid option: –with-nghttp2”
How to Use cURL HTTP/2 on macOS的更多相关文章
- 安装kubuctl
安装和设置kubectl 使用Kubernetes命令行工具kubectl在Kubernetes上部署和管理应用程序.使用kubectl,可以检查集群资源; 创建,删除和更新组件. 以下是安装kube ...
- Fuchsia OS入门官方文档
Fuchsia Pink + Purple == Fuchsia (a new Operating System) Welcome to Fuchsia! This document has ever ...
- Swift 3 and OpenGL on Linux and macOS with GLFW
https://solarianprogrammer.com/2016/11/19/swift-opengl-linux-macos-glfw/ Swift 3 and OpenGL on Linux ...
- 在macOS Sierra 10.12搭建PHP开发环境
macOS Sierra 11.12 已经帮我们预装了 Ruby.PHP(5.6).Perl.Python 等常用的脚本语言,以及 Apache HTTP 服务器.由于 nginx 既能作为 HTTP ...
- How to convert webp to png/jpg/gif in MacOS
Environment I'm using OS X 10.11.4 and have homebrew 1.0.5 installed. Introduction I recently downlo ...
- MacOS X Terminal中设置代理
MacOS X中,即使在网络设置中配置了代理连接,Terminal中也不能访问不可描述的东西,需要额外设置. 我用的是Shadowsocks,使用privoxy搭建了本地的代理服务器,地址是http: ...
- macOS 安装 wget
适用于macOS Sierra Apple Store下载安装Xcode 安装Homebrew包管理,类似于Ubuntu下的apt-get: 终端下输入 ruby -e "$(curl -f ...
- 在MacOS和iOS系统中使用OpenCV
在MacOS和iOS系统中使用OpenCV 前言 OpenCV 是一个开源的跨平台计算机视觉库,实现了图像处理和计算机视觉方面的很多通用算法. 最近试着在 MacOS 和 iOS 上使用 OpenCV ...
- luarocks在macOS系统上的安装
luarocks是基于lua开发的一个包管理工具,所以在安装luarocks之前需要先安装lua(见博客同目录下“lua在MacOS系统上的安装”).具体的安装步骤如下: 1.源码安装部署luaroc ...
- [转]在MacOS和iOS系统中使用OpenCV
OpenCV 是一个开源的跨平台计算机视觉库,实现了图像处理和计算机视觉方面的很多通用算法. 最近试着在MacOS和iOS上使用OpenCV,发现网上关于在MacOS和iOS上搭建OpenCV的资料很 ...
随机推荐
- KubeSphere 3.2.0 发布:带来面向 AI 场景的 GPU 调度与更灵活的网关
现如今最热门的服务器端技术是什么?答案大概就是云原生!KubeSphere 作为一个以 Kubernetes 为内核的云原生分布式操作系统,也是这如火如荼的云原生热潮中的一份子.KubeSphere ...
- QT creator中cmake管理项目,如何引入外部库(引入Eigen库为例)
在Eigen的官网下载压缩包[点我进入] 解压到当前项目的根目录(当然你也可以自己选择目录) 在当前项目的CMakeLists.txt任意位置加入这句话include_directories(${CM ...
- C++多线程应用
一个进程就是一个程序,一个程序里不止一个功能,每个功能的实现就可以交给一个线程去完成.一个进程就像是一个工程,这个工程里,有设计,有监理,有施工,就相当于三个线程,各干各的又相互配合. https:/ ...
- Git命令缩写
g = 'git' ga = 'git add' gaa='git add --all' gapa='git add --patch' gb='git branch' gba='git branch ...
- 定位模组LuatOS快速入门:源UART串口通信
合宙Air201资产定位模组--是一个集成超低功耗4G通信.语音通话.超低功耗定位.计步.震动.Type-C.充电.放音.录音等功能的超小PCBA. 内部集成高效.简单.可靠的LuatOS语言,旨在帮 ...
- Emoji表情字符大全增强你的表达能力-记事本也可以有情感,总有一个您用得上,复制粘贴即可,赶紧收藏关注!!!
这是手绘的吗?不,它是Emoji表情字符,就是普通的文本,你不相信? ️️️️️️ 上面的内容,你看得见吗?尝试选中复制一下,再粘贴到其它地方? 我在PC上和Android手机上操作都是正常的 这是记 ...
- Python脚本消费多个Kafka topic
在Python中消费多个Kafka topic,可以使用kafka-python库,这是一个流行的Kafka客户端库.以下是一个详细的代码示例,展示如何创建一个Kafka消费者,并同时消费多个Kafk ...
- Python网络爬虫之requests模块2
Python网络爬虫之requests模块(2) 今日内容 session处理cookie proxies参数设置请求代理ip 基于线程池的数据爬取 知识点回顾 xpath的解析流程 bs4的解析流程 ...
- Apache Tomcat AJP 实现负载均衡
大部分一开始接触WEB服务器的人可能和我一样对为什么有Apache又有Tomcat服务器感到奇怪(它们还都是Apache开发的呵呵),其实他们不是冗余的服务器,虽然他们都能对外提供WEB服务器,但总的 ...
- Java线程:线程的调度-守护线程——Java线程:线程的调度-合并——Java线程:新特征-障碍器——Java线程:大总结
Java线程:线程的调度-守护线程 守护线程与普通线程写法上基本么啥区别,调用线程对象的方法setDaemon(true),则可以将其设置为守护线程. 守护线程使用的情况较少,但并非无用,举例 ...