Configuring Debugger for Jruby in vscode

jruby

Recently, I configured a debugger for my jruby application on VScode. I have spent almost 1 day on this and few posts discuss this issue. My jruby version is 9.2.9.0. so I can guarantee the following steps definitely will work for this version.

Step 1: Install debug related gems

gem install ruby-debug-ide -v 0.7.2
gem install ruby-debug -v 0.11.0
gem install ruby-debug-base -v 0.11.0

Step 2: Configuring launch.json

  1. Create a folder “.vscode” at the root directory of the project
  2. Create a file launch.json and add following content
{
    "version": "0.2.0",
    "configurations": [
      {
        "name": "Project Name",
        "type": "Ruby",
        "request": "launch",
        "cwd": "${workspaceRoot}",
        "env": {
          "JRUBY_OPTS": "--debug -X+O"
        },
        "program": "${workspaceRoot}/bin/rails",
        "args": ["server", "-p", "5000"]
      }
    ]
  }

Then you will get option to run the project in debug mode, Please refer below image

Debugger

Running this will start the server at port 5000.

In case of error “address already in use” use following command to kill the process

lsof -i:5000 // You will all the process with their Id
kill -9 <PID> // you will get PID from above command

In case you are facing the following error “Debugger terminal error: Process failed: spawn rdebug-ide ENOENT”

Copy the env property of this comment to update it as per your configuration which can easily be found using this comment

Related Post

2 Replies to “Configuring Debugger for Jruby in vscode”

Comments are closed.