You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

macOS 12下因SSL错误无法安装puma gem的问题求助

Puma Gem 编译失败问题解决

问题背景

执行bundle install安装puma gem时触发原生扩展编译错误,核心问题是代码中调用的SSL_CTX_get0_param函数在当前链接的OpenSSL版本中未被声明,导致C99编译报错。环境信息如下:

  • Ruby 3.0.6(通过rvm 1.29.12-next安装)
  • macOS 12.6.1
  • 已通过Homebrew安装OpenSSL,但Ruby编译时未正确关联该版本
  • 因兼容Heroku heroku-20平台,无法升级Ruby版本

错误日志

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.                                                                                                                                                                                                                                                   [0/383]
                                                                               
current directory: /Users/tony/.rvm/gems/ruby-3.0.6/gems/puma-6.3.0/ext/puma_http11                                                                        
/Users/tony/.rvm/rubies/ruby-3.0.6/bin/ruby -I /Users/tony/.rvm/rubies/ruby-3.0.6/lib/ruby/3.0.0 -r ./siteconf20230713-8369-4of5qc.rb extconf.rb              
checking for BIO_read() in -llibcrypto... no
checking for BIO_read() in -lcrypto... yes
checking for SSL_CTX_new() in -lssl... yes
checking for openssl/bio.h... yes 
checking for DTLS_method() in openssl/ssl.h... no
checking for SSL_CTX_set_session_cache_mode(NULL, 0) in openssl/ssl.h... yes
checking for TLS_server_method() in openssl/ssl.h... no
checking for SSL_CTX_set_min_proto_version(NULL, 0) in openssl/ssl.h... no
checking for X509_STORE_up_ref()... no
checking for SSL_CTX_set_ecdh_auto(NULL, 0) in openssl/ssl.h... no
checking for SSL_CTX_set_dh_auto(NULL, 0) in openssl/ssl.h... no
checking for SSL_get1_peer_certificate() in openssl/ssl.h... no
checking for Random.bytes... yes
creating Makefile            
                                                                               
current directory: /Users/tony/.rvm/gems/ruby-3.0.6/gems/puma-6.3.0/ext/puma_http11                                                                           
make DESTDIR\= clean    
                                                                               
current directory: /Users/tony/.rvm/gems/ruby-3.0.6/gems/puma-6.3.0/ext/puma_http11                                                                           
make DESTDIR\=                 
compiling http11_parser.c       
compiling mini_ssl.c      
mini_ssl.c:329:32: error: implicit declaration of function 'SSL_CTX_get0_param' is invalid in C99 [-Werror,-Wimplicit-function-declaration]                    
    X509_VERIFY_PARAM *param = SSL_CTX_get0_param(ctx);
                               ^
mini_ssl.c:329:32: note: did you mean 'SSL_CTX_set1_param'?
/Users/tony/.rvm/usr//include/openssl/ssl.h:1824:5: note: 'SSL_CTX_set1_param' declared here                                                                  
int SSL_CTX_set1_param(SSL_CTX *ctx, X509_VERIFY_PARAM *vpm);
    ^                           
mini_ssl.c:329:24: warning: incompatible integer to pointer conversion initializing 'X509_VERIFY_PARAM *' (aka 'struct X509_VERIFY_PARAM_st *') with an expression of type 'int' [-Wint-conversion]                                                                                                                         
    X509_VERIFY_PARAM *param = SSL_CTX_get0_param(ctx);
                       ^       ~~~~~~~~~~~~~~~~~~~~~~~
1 warning and 1 error generated.    
make: *** [mini_ssl.o] Error 1                                                        

make failed, exit code 2

解决方法

1. 指定兼容的Puma版本

Puma 6.x系列依赖较高版本的OpenSSL API,而Ruby 3.0.6搭配的系统OpenSSL版本不支持SSL_CTX_get0_param。在Gemfile中锁定兼容的Puma版本:

gem 'puma', '~> 5.6.5'

执行bundle install完成安装。

2. 重新编译Ruby并关联Homebrew的OpenSSL

确保Ruby编译时使用Homebrew安装的新版OpenSSL:

  1. 获取Homebrew OpenSSL的安装路径:
# 针对OpenSSL 1.1(推荐兼容Ruby 3.0)
brew --prefix openssl@1.1
# 若安装的是OpenSSL 3,执行:brew --prefix openssl@3
  1. 用rvm重新安装Ruby 3.0.6,指定OpenSSL路径:
rvm reinstall 3.0.6 --with-openssl-dir=$(brew --prefix openssl@1.1)
  1. 重新执行bundle install

3. 临时禁用编译警告转错误

若上述方案无法执行,可临时设置环境变量跳过该错误:

CFLAGS="-Wno-error=implicit-function-declaration" bundle install

内容的提问来源于stack exchange,提问作者Tony Beninate

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 12:44:56