DEV Community

Cover image for How-to integrate debug gem in VS Code - debugger by Ruby core team
Eugene Kozlov
Eugene Kozlov

Posted on • Updated on

How-to integrate debug gem in VS Code - debugger by Ruby core team

Few days ago I found at Github very interesting repo by Ruby core team - ruby/debug: Debugging functionality for Ruby. I used it in my pet-project, and it works awesome! Also I found out that it is included in Rails 7 app template by default. So I think this debugger is really strong opponent to rebornix.ruby extension and debugger which dont have new releases from 2021.

Contents below is short guide how to setup it fast.

Requirements

  • Ruby installed through .rbenv or asdf
  • Bundler gem
  • VS Code

Setup Guide

  1. Create .ruby-version file in root of project if it not already exists.
$ echo "3.0.2" > .ruby-version
Enter fullscreen mode Exit fullscreen mode
  1. Append to Gemfile
group :development, :test do
  gem "debug", platforms: %i[ mri mingw x64_mingw ]
end
Enter fullscreen mode Exit fullscreen mode
  1. Run in terminal
$ bundler binstubs debug bundler
Enter fullscreen mode Exit fullscreen mode
  1. Install extension

  2. Copy to .vscode/launch.json

{
    "version": "0.2.0",
    "configurations": [
      {
        "name": "Start rails server",
        "type": "rdbg",
        "request": "launch",
        "cwd": "${workspaceFolder}",
        "command": "",
        "script": "${workspaceFolder}/bin/rails",
        "useBundler": true,
        "pathToBundler": "${workspaceFolder}/bin/bundle",
        "rdbgPath": "${workspaceFolder}/bin/rdbg",
        "args": ["s"],
      }
    ]
  }
Enter fullscreen mode Exit fullscreen mode

Thats all! Open Run & Debug panel & start debugging!


If you want to boost your VS Code editor for Ruby, you can also check my guide - Complete Guide to setup VS Code for Ruby on Rails (Debugger, Linter, Completion, Formatting)

Thank you for reading, I hope this article was helpful for you!

Top comments (0)