VSCode 需手动配置 Ruby 解释器路径、启用 Solargraph、显式指定 rubyVersion 和 pathToBundler,并确保 bundle exec 环境生效,否则调试、补全、依赖均失效。
rbenv 或 rvm 装 ruby 本身不是 vscode 的事,vscode 只负责识别、调试和补全——配置不对,ruby 命令能跑,但 launch.json 会找不到解释器,solargraph 会连不上,bundle install 的 gem 也常被无视。
确认 Ruby 解释器路径并设为 VSCode 默认
VSCode 不自动继承 shell 的 PATH(尤其 macOS 上用 rbenv 或 rvm 时),它可能只看到系统自带的 Ruby(如 /usr/bin/ruby),导致 bundle、rails 命令报错“command not found”。
- 在终端运行
which ruby,记下输出(例如/Users/you/.rbenv/shims/ruby或/Users/you/.rvm/rubies/ruby-3.2.2/bin/ruby) - 打开 VSCode 设置(
Cmd+,),搜索ruby interpreter path,填入上面路径 - 如果用
rbenv,别填~/.rbenv/shims/ruby—— 它是 bash 函数代理,VSCode 执行不了;应填~/.rbenv/versions/3.2.2/bin/ruby(用rbenv version确认当前版本)
安装并启用 Solargraph 扩展(非可选)
没有 solargraph,VSCode 对 Ruby 几乎没有智能提示、跳转或文档支持。它不是装个插件就完事——服务端必须手动启动并匹配项目 Ruby 版本。
- 先在项目根目录运行:
gem install solargraph
- 确保
solargraph使用的是当前项目的 Ruby:运行ruby -v和which solargraph,二者PATH应指向同一rbenv或rvm版本 - 在 VSCode 中按
Cmd+Shift+P→ 输入Solargraph: Restart,观察右下角状态栏是否显示Solargraph is running - 若提示 “Failed to start Solargraph”,检查终端能否直接执行
solargraph stdio;不能则说明solargraph不在当前 Ruby 的GEM_PATH下
调试配置必须显式指定 rubyVersion 和 pathToBundler
VSCode 的 Ruby 调试器(rebornix.ruby 已弃用,现主流用 fxa96.ruby-debug-ide 或官方 ruby-rdbg)默认不读 .ruby-version 或 Gemfile,不配就崩。
Android文档-开发者指南-第一部分:入门-中英文对照版 Android提供了丰富的应用程序框架,它允许您在Java语言环境中构建移动设备的创新应用程序和游戏。在左侧导航中列出的文档提供了有关如何使用Android的各种API来构建应用程序的详细信息。第一部分:Introduction(入门) 0、Introduction to Android(引进到Android) 1、Application Fundamentals(应用程序基础) 2、Device Compatibility(设备兼容性) 3、
- 生成调试配置:
Cmd+Shift+P→Debug: Open launch.json→ 选Ruby - 在
configurations里补充:{ "type": "rdbg", "name": "Debug Current File", "request": "launch", "script": "${file}", "rubyVersion": "3.2.2", "pathToBundler": "/Users/you/.rbenv/shims/bundle" } -
rubyVersion必须与.ruby-version一致;pathToBundler必须是 shim 路径(不是bundle命令本身),否则断点不触发、binding.irb失效
Bundle 依赖不生效?检查 VSCode 是否用了错误的 GEM_HOME
常见现象:终端里 bundle exec rails s 正常,VSCode 里运行 RSpec 却报 cannot load such file -- rspec/core。本质是 VSCode 启动的进程没加载 bundle exec 环境。
- 不要依赖全局
rspec命令;在tasks.json或调试配置中,一律用bundle exec前缀:"command": "bundle exec rspec"
- 在 VSCode 设置中搜
terminal integrated env,添加环境变量:"RUBYOPT": "-rbundler/setup"
(仅当项目有Gemfile时有效) - 最稳方案:关掉 VSCode,从终端用
code .启动——这样它能完整继承 shell 的rbenv/rvm环境变量
Ruby 开发环境的脆弱点不在 VSCode 插件多寡,而在解释器路径、GEM_HOME、bundle shim 三者是否对齐。少一个,require 就失败,debugger 就静默退出,solargraph 就标红整个文件。









