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

Apple M1 macOS 14.3下Ruby安装在make -j 8步骤失败求助

Apple M1芯片macOS 14.3下Ruby安装失败的解决方案

问题概述

使用rbenv、rvm、asdf三款工具安装Ruby时,均在make -j 8步骤失败,核心错误如下:

  • openssl扩展无法编译,提示找不到OpenSSL库
  • psych扩展编译失败,原因是libyaml为x86_64架构,与M1的arm64架构不兼容

环境信息:

  • 芯片:Apple M1 (arm64)
  • 系统:macOS 14.3 (Sonoma)
  • 目标Ruby版本:3.3.0

报错日志

asdf安装全程日志

asdf install ruby latest 
ruby-build: using openssl@3 from homebrew
==> Downloading ruby-3.3.0.tar.gz...
-> curl -q -fL -o ruby-3.3.0.tar.gz https://cache.ruby-lang.org/pub/ruby/3.3/ruby-3.3.0.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 21.0M  100 21.0M    0     0  8732k      0  0:00:02  0:00:02 --:--:-- 8734k
==> Installing ruby-3.3.0...
ruby-build: using libyaml from homebrew
ruby-build: using gmp from homebrew
-> ./configure "--prefix=$HOME/.asdf/installs/ruby/3.3.0" --with-openssl-dir=/usr/local/opt/openssl@3 --enable-shared --with-libyaml-dir=/usr/local/opt/libyaml --with-gmp-dir=/usr/local/opt/gmp --with-ext=openssl,psych,+
-> make -j 8
*** Following extensions are not compiled:
openssl:
        Could not be configured. It will not be installed.
        /private/var/folders/hz/hfxt6dnj14v6_6qt7t23ppm80000gn/T/ruby-build.20240226205446.26544.yrtoY7/ruby-3.3.0/ext/openssl/extconf.rb:122: OpenSSL library could not be found. You might want to use --with-openssl-dir=<dir> option to specify the prefix where OpenSSL is installed.
        Check /var/folders/hz/hfxt6dnj14v6_6qt7t23ppm80000gn/T/ruby-build.20240226205446.26544.yrtoY7/ruby-3.3.0/ext/openssl/mkmf.log for more details.
psych:
        Could not be configured. It will not be installed.
        Check /var/folders/hz/hfxt6dnj14v6_6qt7t23ppm80000gn/T/ruby-build.20240226205446.26544.yrtoY7/ruby-3.3.0/ext/psych/mkmf.log for more details.

BUILD FAILED (macOS 14.3 on arm64 using ruby-build 20240221)

You can inspect the build directory at /var/folders/hz/hfxt6dnj14v6_6qt7t23ppm80000gn/T/ruby-build.20240226205446.26544.yrtoY7
See the full build log at /var/folders/hz/hfxt6dnj14v6_6qt7t23ppm80000gn/T/ruby-build.20240226205446.26544.log

关键错误详情

OpenSSL库识别失败

=== Checking for required stuff failed. ===
Makefile wasn't created. Fix the errors above.
/private/var/folders/hz/hfxt6dnj14v6_6qt7t23ppm80000gn/T/ruby-build.20240226205446.26544.yrtoY7/ruby-3.3.0/ext/openssl/extconf.rb:122: OpenSSL library could not be found. You might want to use --with-openssl-dir=<dir> option to specify the prefix where OpenSSL is installed.
    /private/var/folders/hz/hfxt6dnj14v6_6qt7t23ppm80000gn/T/ruby-build.20240226205446.26544.yrtoY7/ruby-3.3.0/ext/openssl/extconf.rb:122:in `<top (required)>'
    ./ext/extmk.rb:219:in `load'
    ./ext/extmk.rb:219:in `block in extmake'
    /private/var/folders/hz/hfxt6dnj14v6_6qt7t23ppm80000gn/T/ruby-build.20240226205446.26544.yrtoY7/ruby-3.3.0/lib/mkmf.rb:314:in `open'
    ./ext/extmk.rb:215:in `extmake'
    ./ext/extmk.rb:634:in `block in <main>'
    ./ext/extmk.rb:630:in `each'
    ./ext/extmk.rb:630:in `<main>'

libyaml架构不兼容

ld: warning: ignoring file '/usr/local/Cellar/libyaml/0.2.5/lib/libyaml-0.2.dylib': found architecture 'x86_64', required architecture 'arm64'
ld: Undefined symbols:
  _yaml_get_version, referenced from:
      _t in conftest-a05b11.o
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 yaml_get_version();
15: int t(void) { yaml_get_version(); return 0; }
/* end */

解决方案

1. 重装arm64架构的依赖库

当前libyaml为x86_64版本,需卸载后重新安装arm64适配版本:

# 强制卸载现有x86_64依赖
brew uninstall --force libyaml openssl@3 gmp

# 确认Homebrew处于arm64模式(M1默认路径为/opt/homebrew/bin/brew)
# 若当前路径为/usr/local,执行切换命令:eval "$(/opt/homebrew/bin/brew shellenv)"

# 重新安装arm64架构的依赖
brew install libyaml openssl@3 gmp

2. 设置环境变量,确保编译工具识别arm64库

执行以下命令临时设置环境变量(需永久生效可添加到~/.zshrc或~/.bashrc):

export PATH="/opt/homebrew/opt/openssl@3/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/openssl@3/lib -L/opt/homebrew/opt/libyaml/lib -L/opt/homebrew/opt/gmp/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@3/include -I/opt/homebrew/opt/libyaml/include -I/opt/homebrew/opt/gmp/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@3/lib/pkgconfig:/opt/homebrew/opt/libyaml/lib/pkgconfig:/opt/homebrew/opt/gmp/lib/pkgconfig"

3. 重新安装Ruby

# 清理之前的安装残留
asdf uninstall ruby 3.3.0
rm -rf ~/.asdf/installs/ruby/3.3.0

# 重新执行安装
asdf install ruby 3.3.0

4. 验证安装结果

# 设置全局Ruby版本
asdf global ruby 3.3.0

# 检查版本及扩展状态
ruby -v
ruby -r openssl -e "puts OpenSSL::VERSION"
ruby -r psych -e "puts Psych::VERSION"

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 08:42:34