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

CentOS 6下Ruby 2.6.10与OpenSSL 3编译失败求助

Ruby 2.6.10 搭配 OpenSSL 3 在 CentOS 6 上编译的解决方案

问题背景

必须使用Ruby 2.6.10版本,基础操作系统为CentOS 6,尝试搭配OpenSSL v3编译该版本Ruby(源码分支:https://github.com/ruby/ruby/tree/v2_6_10),编译时出现以下错误:

2023-07-11T04:27:11.0498806Z ossl_pkey_rsa.c:872:1: warning: 'RSA_set0_crt_params' is deprecated: Since       OpenSSL 3.0 [-Wdeprecated-declarations]
2023-07-11T04:27:11.0499056Z In file included from /usr/local_ssl_3.0.0/include/openssl/x509.h:36:0,
2023-07-11T04:27:11.0499267Z                  from /usr/local_ssl_3.0.0/include/openssl/x509v3.h:25,
2023-07-11T04:27:11.0499451Z                  from ossl.h:23,
2023-07-11T04:27:11.0499626Z                  from ossl_pkey_rsa.c:10:
2023-07-11T04:27:11.0499829Z /usr/local_ssl_3.0.0/include/openssl/rsa.h:209:27: note: declared here
2023-07-11T04:27:11.0500092Z  OSSL_DEPRECATEDIN_3_0 int RSA_set0_crt_params(RSA *r,
2023-07-11T04:27:11.0500279Z                            ^~~~~~~~~~~~~~~~~~~
2023-07-11T04:27:11.0535494Z In file included from ../.././include/ruby.h:33:0,
2023-07-11T04:27:11.0536068Z                  from ossl.h:16,
2023-07-11T04:27:11.0536408Z                  from ossl_pkey_rsa.c:10:
2023-07-11T04:27:11.0536922Z ossl_pkey_rsa.c: In function 'Init_ossl_rsa':
2023-07-11T04:27:11.0537392Z ossl_pkey_rsa.c:877:58: error: 'RSA_SSLV23_PADDING' undeclared (first use in this function); did you mean 'RSA_NO_PADDING'?
2023-07-11T04:27:11.0537854Z  #define DefRSAConst(x) rb_define_const(cRSA, #x, INT2NUM(RSA_##x))
2023-07-11T04:27:11.0538062Z                                                           ^
2023-07-11T04:27:11.0538545Z ../.././include/ruby/ruby.h:261:33: note: in definition of macro 'RB_INT2FIX'
2023-07-11T04:27:11.0538956Z  #define RB_INT2FIX(i) (((VALUE)(i))<<1 | RUBY_FIXNUM_FLAG)
2023-07-11T04:27:11.0539289Z                                  ^
2023-07-11T04:27:11.0539750Z ../.././include/ruby/ruby.h:1594:20: note: in expansion of macro 'RB_INT2NUM'
2023-07-11T04:27:11.0540018Z  #define INT2NUM(x) RB_INT2NUM(x)
2023-07-11T04:27:11.0540188Z                     ^~~~~~~~~~
2023-07-11T04:27:11.0540448Z ossl_pkey_rsa.c:877:50: note: in expansion of macro 'INT2NUM'
2023-07-11T04:27:11.0540671Z  #define DefRSAConst(x) rb_define_const(cRSA, #x, INT2NUM(RSA_##x))
2023-07-11T04:27:11.0540857Z                                                   ^~~~~~~
2023-07-11T04:27:11.0541109Z ossl_pkey_rsa.c:942:5: note: in expansion of macro 'DefRSAConst'
2023-07-11T04:27:11.0541310Z      DefRSAConst(SSLV23_PADDING);

编译OpenSSL v3的步骤为:

git clone git://git.openssl.org/openssl.git openssl-3.0.0
cd openssl-3.0.0
git checkout openssl-3.0.0
export PATH=/usr/local_perl_5_24_1/bin:$PATH
./config --prefix=/usr/local_ssl_3.0.0 shared -no-ssl2 -no-ec -no-ec2m -no-ecdh
make depend
make
sudo make install_sw

解决方案

Ruby 2.6.10原生不支持OpenSSL 3,因为OpenSSL 3移除了RSA_SSLV23_PADDING这类旧API,并且标记了一批函数为废弃。要成功编译,需要对Ruby源码做补丁适配,步骤如下:

1. 准备Ruby源码

如果还没克隆源码,执行:

git clone https://github.com/ruby/ruby.git
cd ruby
git checkout v2_6_10

2. 修复OpenSSL 3 API兼容问题

编辑ext/openssl/ossl_pkey_rsa.c文件:

  • 解决RSA_SSLV23_PADDING未定义错误:在文件开头(#include "ossl.h"之后)添加以下代码:
    #ifndef RSA_SSLV23_PADDING
    #define RSA_SSLV23_PADDING RSA_PKCS1_PADDING
    #endif
    
  • 解决RSA_set0_crt_params废弃警告:可以通过编译参数忽略该警告,无需修改代码。

3. 编译Ruby并指定OpenSSL 3路径

先设置环境变量指向OpenSSL 3的安装目录:

export PKG_CONFIG_PATH=/usr/local_ssl_3.0.0/lib/pkgconfig
export LD_LIBRARY_PATH=/usr/local_ssl_3.0.0/lib:$LD_LIBRARY_PATH

然后执行配置和编译命令,添加忽略废弃警告的CFLAGS参数:

./configure --prefix=/usr/local/ruby-2.6.10 --with-openssl-dir=/usr/local_ssl_3.0.0 CFLAGS="-Wno-deprecated-declarations"
make
sudo make install

4. 验证安装结果

安装完成后,检查Ruby关联的OpenSSL版本:

/usr/local/ruby-2.6.10/bin/ruby -r openssl -e 'puts OpenSSL::OPENSSL_VERSION'

如果输出包含OpenSSL 3.0.0,说明编译成功。

注意事项

  • CentOS 6的系统工具链较老,编译时可能需要升级gcc到7.x版本(可通过devtoolset-7获取),否则可能遇到其他编译错误。
  • 上述补丁属于临时适配方案,Ruby 2.6系列已停止官方维护,长期使用建议升级到支持OpenSSL 3的Ruby版本(如Ruby 3.0及以上)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 08:39:57