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

Apple M2设备Rails项目bundle install安装racc失败求助

问题描述

刚换了搭载Apple M2芯片的新设备,打算创建Rails新项目,但执行bundle install时总是报错,具体错误如下:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/a1111/RubymineProjects/FasterThanLightTest/FasterThanLightTest/vendor/cache/ruby/3.0.0/gems/racc-1.6.2/ext/racc/cparse
/Users/a1111/.rvm/rubies/ruby-3.0.0/bin/ruby -I /Users/a1111/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0 -r ./siteconf20230227-63071-piv0lx.rb extconf.rb
checking for rb_block_call()... no
checking for rb_ary_subseq()... no
creating Makefile

后续还会出现以下提示:

An error occurred while installing racc (1.6.2), and Bundler cannot continue.
Make sure that `gem install racc -v '1.6.2' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  rails was resolved to 7.0.4.2, which depends on
    actioncable was resolved to 7.0.4.2, which depends on
      actionpack was resolved to 7.0.4.2, which depends on
        actionview was resolved to 7.0.4.2, which depends on
          rails-dom-testing was resolved to 2.0.3, which depends on
            nokogiri was resolved to 1.14.2, which depends on
              racc

已安装最新版Xcode命令行工具,当前Ruby版本3.0.0,Rails版本7.0.4,请问问题原因是什么?

问题原因分析
  • Ruby版本与Apple Silicon架构兼容性不足:Ruby 3.0.0发布早于Apple M2芯片,官方预编译包未针对ARM64架构优化,编译racc这类原生扩展时,会出现核心函数(如rb_block_call()、rb_ary_subseq())检测失败的情况。
  • RVM编译Ruby时架构参数缺失:若通过RVM安装Ruby 3.0.0,编译过程中未明确指定ARM64架构,生成的Ruby二进制文件无法适配M2芯片的系统函数,进而阻碍原生gem的编译。
  • racc版本适配问题:racc 1.6.2存在与ARM64架构下Ruby 3.0.0的兼容性bug,部分依赖的Ruby核心函数在该环境下无法被正确识别,导致编译失败。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.30 10:00:02