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

Mac OS Ventura下Ruby 2.7.5安装失败(OpenSSL配置错误)

安装Ruby 2.7.5适配React Native 0.70时OpenSSL编译失败的解决方法

问题背景

为适配React Native 0.70,在Mac OS Ventura系统中尝试安装Ruby 2.7.5并指定使用OpenSSL 1.1,执行命令:

CONFIG_PATH=/usr/local/opt/openssl@1.1/lib/pkgconfig rvm reinstall 2.7.5 --with-openssl-lib=/usr/local/opt/openssl@1.1 --with-openssl-include=/usr/local/opt/openssl@1.1

安装失败,日志提示OpenSSL扩展未编译,ext/openssl/mkmf.log中出现t_open未定义、-lnsl/-lsocket库找不到、LIBRESSL_VERSION_NUMBER未定义等错误。

错误日志详情

conftest.c:14:57: error: use of undeclared identifier 't_open'
 t(void) { void ((*volatile p)()); p = (void ((*)()))t_open; return !p; }
                                                        ^
1 error generated.
checked program was:
/* begin */
 1: #include "ruby.h"
 2:
 3: /*top*/
 4: extern int t(void);
 5: int main(int argc, char **argv)
 6: {
 7:   if (argc > 1000000) {
 8:     int (* volatile tp)(void)=(int (*)(void))&t;
 9:     printf("%d", (*tp)());
10:   }
11:
12:   return !!argv[argc];
13: }
14: int t(void) { void ((*volatile p)()); p = (void ((*)()))t_open; return !p; }

----------------

ld: library not found for -lnsl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: /*top*/
4: extern int t(void);
5: int main(int argc, char **argv)
6: {
7:   if (argc > 1000000) {
8:     int (* volatile tp)(void)=(int (*)(void))&t;
9:     printf("%d", (*tp)());
10:   }
11:
12:   return !!argv[argc];
13: }
14: extern void t_open();
15: int t(void) { t_open(); return 0; }
/* end */

------------------------
conftest.c:14:57: error: use of undeclared identifier 'socket'
int t(void) { void ((*volatile p)()); p = (void ((*)()))socket; return !p; }
                                                      ^
1 error generated.
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: /*top*/
4: extern int t(void);
5: int main(int argc, char **argv)
6: {
7:   if (argc > 1000000) {
8:     int (* volatile tp)(void)=(int (*)(void))&t;
9:     printf("%d", (*tp)());
10:   }
11:
12:   return !!argv[argc];
13: }
14: int t(void) { void ((*volatile p)()); p = (void ((*)()))socket; return !p; }
/* end */

-----------------------------

ld: library not found for -lsocket
clang: error: linker command failed with exit code 1 (use -v to see invocation)
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: /*top*/
4: extern int t(void);
5: int main(int argc, char **argv)
6: {
7:   if (argc > 1000000) {
8:     int (* volatile tp)(void)=(int (*)(void))&t;
9:     printf("%d", (*tp)());
10:   }
11:
12:   return !!argv[argc];
13: }
14: extern void socket();
15: int t(void) { socket(); return 0; }
/* end */

--------------------
conftest.c:6:3: error:
# error
  ^
conftest.c:7:1: error: expected identifier or '('
|:/ === LIBRESSL_VERSION_NUMBER undefined === /:|
^
2 errors generated.
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <openssl/opensslv.h>
4: /*top*/
5: #ifndef LIBRESSL_VERSION_NUMBER
6: # error
7: |:/ === LIBRESSL_VERSION_NUMBER undefined === /:|
8: #endif
/* end */

---------------

/Users/dcent/.rvm/src/ruby-2.7.5/ext/openssl/extconf.rb:111: OpenSSL >= 1.0.1, < 3.0.0 or LibreSSL >= 2.5.0 is required
      /Users/dcent/.rvm/src/ruby-2.7.5/ext/openssl/extconf.rb:111:in `<top (required)>'
      ./ext/extmk.rb:214:in `load'
      ./ext/extmk.rb:214:in `block in extmake'
      /Users/dcent/.rvm/src/ruby-2.7.5/lib/mkmf.rb:331:in `open'
      ./ext/extmk.rb:210:in `extmake'
      ./ext/extmk.rb:572:in `block in <main>'
      ./ext/extmk.rb:568:in `each'
      ./ext/extmk.rb:568:in `<main>'

解决步骤

  • 确认OpenSSL 1.1已安装:
    执行brew list openssl@1.1检查,未安装则运行brew install openssl@1.1。
  • 设置完整的环境变量,确保编译工具能正确找到OpenSSL 1.1:
    export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"
    export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
    export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"
    export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"
    
  • 使用简化的RVM命令重新安装Ruby 2.7.5,依赖环境变量自动识别OpenSSL路径:
    rvm reinstall 2.7.5 --with-openssl-dir=/usr/local/opt/openssl@1.1
    
  • 若仍报-lnsl/-lsocket错误,添加参数忽略这些非Mac系统默认库:
    rvm reinstall 2.7.5 --with-openssl-dir=/usr/local/opt/openssl@1.1 --with-ldflags="-L/usr/local/opt/openssl@1.1/lib" --with-cppflags="-I/usr/local/opt/openssl@1.1/include" --without-tcl --without-tk
    
  • 确保Xcode命令行工具是最新状态:
    执行xcode-select --install安装或更新,再运行sudo xcodebuild -license accept接受许可证。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 10:34:50