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

React Native 0.71.1项目Ruby相关报错及安装问题求助

React Native 0.71.1 新项目环境报错及解决步骤

问题汇总

1. 进入项目目录时的RVM报错

RVM used your Gemfile for selecting Ruby, it is all fine - Heroku does that too,
you can ignore these warnings with 'rvm rvmrc warning ignore /Users/transformhub/Desktop/rnapp/Gemfile'.
To ignore the warning for all files run 'rvm rvmrc warning ignore allGemfiles'.

Unknown ruby interpreter version (do not know how to handle): File.readFile.join__dir__,.ruby-version.strip.

2. iOS目录执行依赖安装命令报错

执行bundle install && RCT_NEW_ARCH_ENABLED=1 bundle exec pod install时出现:

[!] There was an error parsing Gemfile: No such file or directory @ rb_sysopen - /Users/transformhub/Desktop/rnapp/.ruby-version. Bundler cannot continue.

from /Users/transformhub/Desktop/rnapp/Gemfile:4
-------------------------------------------
# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version

ruby File.read(File.join(dir, '.ruby-version')).strip

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

3. rbenv安装Ruby 2.7.6时编译报错

执行rbenv install 2.7.6出现:

readline.c:1904:37: error: use of undeclared identifier 'username_completion_function'; did you mean 'rl_username_completion_function'?
                                    rl_username_completion_function);
                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

readline.c:79:42: note: expanded from macro 'rl_username_completion_function'
# define rl_username_completion_function username_completion_function
                                         ^
/opt/homebrew/opt/readline/include/readline/readline.h:494:14: note: 'rl_username_completion_function' declared here
extern char *rl_username_completion_function (const char *, int);
             ^
1 error generated.
make[2]: *** [readline.o] Error 1

当前环境信息

  • Ruby版本:ruby 3.2.0 (2022-12-25 revision a528908271) [arm64-darwin22]
  • PATH输出:
/Users/transformhub/.rbenv/shims:/Users/transformhub/.rbenv/shims:/Users/transformhub/.rbenv/bin:/Users/transformhub/.rbenv/shims:/opt/homebrew/opt/ruby/bin:/Users/transformhub/.gem/bin:/Users/transformhub/.pyenv/shims:/Users/transformhub/.pyenv/bin:/Users/transformhub/.pyenv/bin:/Users/transformhub/.rbenv/shims:/Users/transformhub/.rbenv/bin:/Library/Frameworks/Python.framework/Versions/3.9/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/transformhub/Desktop/flutter/bin :/usr/local/go/bin:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Apple/usr/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Applications/Postgres.app/Contents/Versions/latest/bin:/Users/transformhub/Library/Android/sdk/platform-tools:/Users/transformhub/Users/transformhub/Desktop/flutter/bin:/Users/transformhub/Android/Sdk/tools:/Users/transformhub/Android/Sdk/tools/bin:/Users/transformhub/Android/Sdk/platform-tools:/Library/Frameworks/Python.framework/Versions/3.9/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/transformhub/Desktop/flutter/bin:/Users/transformhub/.cargo/bin:/Users/transformhub/.rvm/bin

解决方案

1. 修复Gemfile解析错误及缺少.ruby-version文件问题

  • 项目根目录创建.ruby-version文件,写入React Native推荐版本:
    echo "2.7.6" > /Users/transformhub/Desktop/rnapp/.ruby-version
    
  • 若Gemfile读取逻辑仍有问题,可临时硬编码版本:将Gemfile第4行替换为:
    ruby "2.7.6"
    

2. 解决RVM与rbenv冲突及目录警告

  • 移除PATH中的RVM路径,避免版本管理工具冲突:编辑~/.zshrc或~/.bashrc,删除包含~/.rvm/bin的行,然后执行:
    source ~/.zshrc # 对应你的shell配置文件
    
  • 若需保留RVM,执行命令忽略Gemfile警告:
    rvm rvmrc warning ignore /Users/transformhub/Desktop/rnapp/Gemfile
    

3. 修复rbenv安装Ruby 2.7.6的readline编译错误

  • 安装兼容的低版本readline:
    brew install readline@8.1
    
  • 指定该readline版本编译安装Ruby:
    RUBY_CONFIGURE_OPTS="--with-readline-dir=$(brew --prefix readline@8.1)" rbenv install 2.7.6
    
  • 切换项目使用该Ruby版本:
    cd /Users/transformhub/Desktop/rnapp
    rbenv local 2.7.6
    

4. 重新执行iOS依赖安装

完成上述步骤后,进入iOS目录重新执行命令:

cd /Users/transformhub/Desktop/rnapp/ios
bundle install && RCT_NEW_ARCH_ENABLED=1 bundle exec pod install

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 20:15:55