How can you launch Ruby on Rails using the built-in Visual Studio Code Launch/Debug features?
How do you fix the
Debugger terminal error: Process failed: spawn rdebug-ide ENOENT
error?

- 2,942
- 4
- 23
- 36
-
1Not really related, but just in case you don't already have it, definitely install [Ruby Solargraph](https://marketplace.visualstudio.com/items?itemName=castwide.solargraph), to make life easier. It is best thing going for intellisense for Ruby, actually got me to switch from RubyMine (at least for writing C extensions). If using Ruby 2.4+, read the end of the description if you get `EventMachine` error. – ForeverZer0 Aug 07 '18 at 08:40
-
@ForeverZer0 - Thanks, this actually really helps me! Trying to switch away from the bloated RubyMine and didn't quite get there yet... – janniks Aug 07 '18 at 09:26
3 Answers
Setup and Launch
- Install the VS Code Ruby plugin (hit ⌘+⇧+P on macOS or ctrl+⇧+P elsewhere and type
ext install
in the prompt, then search forruby
) - Install some required Ruby gems
gem install ruby-debug-ide
gem install debase
- Add a launch configuration in Visual Studio Code (example configuration shown below)
{
"name": "Rails server",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/bin/rails",
"env": {
"PATH": "YOUR_PATH_HERE",
"GEM_HOME": "YOUR_GEM_HOME_HERE",
"GEM_PATH": "YOUR_GEM_PATH_HERE",
"RUBY_VERSION": "YOUR_RUBY_VERSION_HERE"
},
"args": [
"server"
]
}
In some cases you might not need to specify the
env
section. In other cases you can launch VS Code using the CLI (i.e. from the terminal), which on some systems automatically sets the correct environment variables.
- Run!
Troubleshooting
If you get the following error
Debugger terminal error: Process failed: spawn rdebug-ide ENOENT
Your environment variables (env
) are most likely not set and the plugin cannot find the necessary binaries.
- Make sure all gems are installed and try running
bundler install --binstubs
if you use bundler. - Make sure the
env
section is set in your launch configuration. Run the following shell command to generate yourenv
:
printf "\n\"env\": {\n \"PATH\": \"$PATH\",\n \"GEM_HOME\": \"$GEM_HOME\",\n \"GEM_PATH\": \"$GEM_PATH\",\n \"RUBY_VERSION\": \"$RUBY_VERSION\"\n}\n\n"
Windows
Make sure to use the correct spelling (and capitalization) of the path
variable, i.e. Path
on Windows
Sources:

- 2,942
- 4
- 23
- 36
-
1Not sure how well it plays with Rails, but [CodeRunner](https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner) might also be handy for quick test runs and debugging also. – ForeverZer0 Aug 07 '18 at 08:43
-
@ForeverZer0 - CodeRunner is awesome for scripts and simple applications. Unfortunately it doesn't really work well with more complex frameworks that do a lot of routing and rendering like Rails... – janniks Aug 07 '18 at 09:25
-
I assumed as much for Rails, but for could still be useful for snippets and such. Just throwing an honorably mention out there. :) – ForeverZer0 Aug 07 '18 at 09:53
-
For all people hitting this error on Windows, despite adding PATH to ENV in launch.json, mind this: https://stackoverflow.com/a/54993121/717732 - check the spelling of PATH on your OS! – quetzalcoatl Sep 03 '19 at 21:05
-
-
I spent most of a day trying to solve this.
I ended up stripping my launch.json config down to the following:
"configurations": [
{
"name": "Rails server",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "/Users/mitch/.rvm/gems/ruby-2.3.0@gg_portal/bin/rails",
"args": [
"server"
],
"useBundler": true,
"pathToRDebugIDE": "/Users/mitch/.rvm/gems/ruby-2.3.0@gg_portal/gems/ruby-debug-ide-0.6.1",
"pathToBundler": "/Users/mitch/.rvm/gems/ruby-2.3.0@gg_portal/wrappers/bundle",
"showDebuggerOutput": true
}
]
Firstly, especially if you're using RVM & have different Gemsets, make sure your paths are consistent with the correct Gemset.
What solved the problem for me was pathToBundler.
which bundle
/Users/mitch/.rvm/gems/ruby-2.3.0@gg_portal/bin/bundle
There looks to be some incompatibility around setting the path to the binstubs bundler (shown above) and the bundler pointed to from /wrappers/ (shown below), so changing pathToBundler to:
"pathToBundler": "/Users/mitch/.rvm/gems/ruby-2.3.0@gg_portal/wrappers/bundle",
solved the problem.
There is a kind of related discussion here:
https://github.com/rails/rails/issues/31193
which talks about binstubs though not specifically VSCode & debugging.

- 1,017
- 1
- 13
- 25
-
Thanks. I also tried "~/.rvm/gems...." so that other users could share but VSCode didn't like it. – jnicho02 Sep 05 '19 at 09:00
-
1
-
I used remote debugger. After I changed `"program": "${workspaceRoot}/bin/rails",` to `"program": "/repo/main/bin/rails",`. the debugger to rails works for me – Canhua Li Oct 11 '22 at 15:24
If you're using a ruby version manager such as rbenv that relies on bash shims, try launching VS Code from the terminal. This should allow VS Code to pick up on the env variables that rbenv sets. Alternatively you can set your env vars in launch.json
, but this is not a very maintainable solution.

- 410
- 3
- 16