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

升级MacOS Monterey后执行rails new命令报错,gem pristine无效如何解决

问题描述

每次使用rails new命令创建Rails应用时都会触发报错,项目文件虽能正常生成,但报错始终无法彻底消除,故障首次出现于升级MacOS Monterey系统后。

已尝试以下操作均无效果:

  • 更新Ruby版本
  • 重新安装Rails
  • 对全量gem执行pristine操作
  • 用chruby安装Ruby后重新部署Rails环境

完整报错日志

Ignoring racc-1.6.0 because its extensions are not built. Try: gem pristine racc --version 1.6.0
Ignoring nio4r-2.5.8 because its extensions are not built. Try: gem pristine nio4r --version 2.5.8
Ignoring websocket-driver-0.7.5 because its extensions are not built. Try: gem pristine websocket-driver --version 0.7.5
      create  
      create  README.md
      create  Rakefile
      create  .ruby-version
      create  config.ru
      create  .gitignore
      create  .gitattributes
      create  Gemfile
         run  git init from "."
Initialized empty Git repository in /Users/rares/Desktop/RoR/app/.git/
      create  package.json
      create  app
      create  app/assets/config/manifest.js
      create  app/assets/stylesheets/application.css
      create  app/channels/application_cable/channel.rb
      create  app/channels/application_cable/connection.rb
      create  app/controllers/application_controller.rb
      create  app/helpers/application_helper.rb
      create  app/javascript/channels/consumer.js
      create  app/javascript/channels/index.js
      create  app/javascript/packs/application.js
      create  app/jobs/application_job.rb
      create  app/mailers/application_mailer.rb
      create  app/models/application_record.rb
      create  app/views/layouts/application.html.erb
      create  app/views/layouts/mailer.html.erb
      create  app/views/layouts/mailer.text.erb
      create  app/assets/images
      create  app/assets/images/.keep
      create  app/controllers/concerns/.keep
      create  app/models/concerns/.keep
      create  bin
      create  bin/rails
      create  bin/rake
      create  bin/setup
      create  bin/spring
      create  bin/yarn
      create  config
      create  config/routes.rb
      create  config/application.rb
      create  config/environment.rb
      create  config/cable.yml
      create  config/puma.rb
      create  config/spring.rb
      create  config/storage.yml
      create  config/environments
      create  config/environments/development.rb
      create  config/environments/production.rb
      create  config/environments/test.rb
      create  config/initializers
      create  config/initializers/application_controller_renderer.rb
      create  config/initializers/assets.rb
      create  config/initializers/backtrace_silencers.rb
      create  config/initializers/content_security_policy.rb
      create  config/initializers/cookies_serializer.rb
      create  config/initializers/cors.rb
      create  config/initializers/filter_parameter_logging.rb
      create  config/initializers/inflections.rb
      create  config/initializers/mime_types.rb
      create  config/initializers/new_framework_defaults_6_1.rb
      create  config/initializers/permissions_policy.rb
      create  config/initializers/wrap_parameters.rb
      create  config/locales
      create  config/locales/en.yml
      create  config/master.key
      append  .gitignore
/Users/rares/.gem/ruby/2.7.2/gems/activesupport-6.1.4.1/lib/active_support/message_encryptor.rb:170:in `auth_data=': couldn't set additional authenticated data (OpenSSL::Cipher::CipherError)
    from /Users/rares/.gem/ruby/2.7.2/gems/activesupport-6.1.4.1/lib/active_support/message_encryptor.rb:170:in `_encrypt'
    from /Users/rares/.gem/ruby/2.7.2/gems/activesupport-6.1.4.1/lib/active_support/message_encryptor.rb:148:in `encrypt_and_sign'
    from /Users/rares/.gem/ruby/2.7.2/gems/activesupport-6.1.4.1/lib/active_support/encrypted_file.rb:88:in `encrypt'
    from /Users/rares/.gem/ruby/2.7.2/gems/activesupport-6.1.4.1/lib/active_support/encrypted_file.rb:61:in `write'
    from /Users/rares/.gem/ruby/2.7.2/gems/activesupport-6.1.4.1/lib/active_support/encrypted_configuration.rb:29:in `write'
    from /Users/rares/.gem/ruby/2.7.2/gems/railties-6.1.4.1/lib/rails/generators/rails/credentials/credentials_generator.rb:30:in `add_credentials_file_silently'
    from /Users/rares/.gem/ruby/2.7.2/gems/railties-6.1.4.1/lib/rails/generators/rails/app/app_generator.rb:194:in `credentials'
    from /Users/rares/.gem/ruby/2.7.2/gems/railties-6.1.4.1/lib/rails/generators/app_base.rb:165:in `public_send'
    from /Users/rares/.gem/ruby/2.7.2/gems/railties-6.1.4.1/lib/rails/generators/app_base.rb:165:in `build'
    from /Users/rares/.gem/ruby/2.7.2/gems/railties-6.1.4.1/lib/rails/generators/rails/app/app_generator.rb:386:in `create_credentials'
    from /Users/rares/.gem/ruby/2.7.2/gems/thor-1.1.0/lib/thor/command.rb:27:in `run'
    from /Users/rares/.gem/ruby/2.7.2/gems/thor-1.1.0/lib/thor/invocation.rb:127:in `invoke_command'
    from /Users/rares/.gem/ruby/2.7.2/gems/thor-1.1.0/lib/thor/invocation.rb:134:in `block in invoke_all'
    from /Users/rares/.gem/ruby/2.7.2/gems/thor-1.1.0/lib/thor/invocation.rb:134:in `each'
    from /Users/rares/.gem/ruby/2.7.2/gems/thor-1.1.0/lib/thor/invocation.rb:134:in `map'
    from /Users/rares/.gem/ruby/2.7.2/gems/thor-1.1.0/lib/thor/invocation.rb:134:in `invoke_all'
    from /Users/rares/.gem/ruby/2.7.2/gems/thor-1.1.0/lib/thor/group.rb:232:in `dispatch'
    from /Users/rares/.gem/ruby/2.7.2/gems/thor-1.1.0/lib/thor/base.rb:485:in `start'
    from /Users/rares/.gem/ruby/2.7.2/gems/railties-6.1.4.1/lib/rails/commands/application/application_command.rb:26:in `perform'
    from /Users/rares/.gem/ruby/2.7.2/gems/thor-1.1.0/lib/thor/command.rb:27:in `run'
    from /Users/rares/.gem/ruby/2.7.2/gems/thor-1.1.0/lib/thor/invocation.rb:127:in `invoke_command'
    from /Users/rares/.gem/ruby/2.7.2/gems/thor-1.1.0/lib/thor.rb:392:in `dispatch'
    from /Users/rares/.gem/ruby/2.7.2/gems/railties-6.1.4.1/lib/rails/command/base.rb:69:in `perform'
    from /Users/rares/.gem/ruby/2.7.2/gems/railties-6.1.4.1/lib/rails/command.rb:48:in `invoke'
    from /Users/rares/.gem/ruby/2.7.2/gems/railties-6.1.4.1/lib/rails/cli.rb:18:in `<top (required)>'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /Users/rares/.gem/ruby/2.7.2/gems/railties-6.1.4.1/exe/rails:10:in `<top (required)>'
    from /usr/local/bin/rails:23:in `load'
    from /usr/local/bin/rails:23:in `<main>'
解决步骤

修复gem扩展未构建报错

该问题是系统升级后旧gem编译依赖的工具链发生变化,且全局rails命令调用了系统自带Ruby版本的依赖导致:

  1. 执行ruby -v确认当前shell激活的是你自行安装的Ruby版本,而非系统自带的2.6.x版本
  2. 执行which rails确认输出路径对应你安装的Ruby版本bin目录,若输出为/usr/local/bin/rails则执行sudo rm /usr/local/bin/rails清理全局旧执行文件
  3. 在当前激活的Ruby环境下重新安装Rails:gem install rails
  4. 重新编译对应版本的扩展gem:gem pristine racc --version 1.6.0 nio4r --version 2.5.8 websocket-driver --version 0.7.5

修复OpenSSL加密报错

该问题是Monterey系统自带OpenSSL版本与Ruby编译依赖的OpenSSL版本不兼容导致:

  1. 用Homebrew安装兼容的OpenSSL 1.1版本:brew install openssl@1.1
  2. 重新编译安装对应版本的Ruby,编译时指定OpenSSL路径(以Ruby 2.7.2为例):
RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.1)" ruby-install ruby 2.7.2
  1. 重新安装Rails及所有依赖gem后,再次执行rails new测试即可

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.28 04:15:04