Skip to content

How to debug Ruby using VS Code

Alexander Straube edited this page Nov 19, 2026 · 2 revisions

If using VS Code, all you have to do is install the Ruby LSP extension to get the extra features in the editor.

Overview

The Ruby LSP is an implementation of the language server protocol for Ruby, used to improve rich features in editors. It is a part of a wider goal to provide a state-of-the-art experience to Ruby developers using modern standards for cross-editor features, documentation and debugging.

VS Code debugging Foreman

Example

Even with the Ruby LSP guide for VS Code stating that you do not necessarily need to install the ruby-lsp gem manually, I found it a lot quicker for the Ruby LSP server to initialize when the ruby-lsp gem is installed upfront using

gem install ruby-lsp

For some development work on the Bolt integration plugin for Foreman I personally have chosen to use an Ubuntu-based devcontainer in order to install all the required prerequisites in a self-contained environment.

In order to aquire the proper versions of NPM and Ruby using mise is a good idea, e.g. my Containerfile looks like this

ARG UBUNTU_VERSION=24.04
FROM ubuntu:${UBUNTU_VERSION}

ENV NODE_VERSION=22
ENV RUBY_VERSION=3.2

...

ADD --chmod=+x https://github.com/jdx/mise/releases/download/v2026.11.9/mise-v2026.11.9-linux-x64 /usr/local/bin/mise

USER ubuntu

RUN mise use -g node@${NODE_VERSION} ruby@${RUBY_VERSION} && \
    echo 'eval $(mise activate)' > ~/.bash_profile && \
    . ~/.bash_profile && \
    npm install -g npm && \
    gem install ruby-lsp

WORKDIR /work

After cloning the foreman and foreman_openbolt repositories I had to create bundler.d/foreman_openbolt.rb with following content inside my working copy of foreman

gem 'foreman_openbolt', :path => '../foreman_openbolt'
gem 'debug'

Afterwards Ruby and NPM dependencies are installled using following commands inside the working copy of foreman

bundler config set --local path vendor
bundler install
npm install

In order to start Foreman for debugging you can use following command

bundler exec rdbg -O -n -c -- foreman start

My .vscode/launch.json for attaching to the Ruby debugger or launching a Firefox instance for debugging looks like this

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Attach to Ruby debugger",
      "type": "ruby_lsp",
      "request": "attach"
    },
    {
      "name": "Launch Firefox",
      "type": "firefox",
      "request": "launch",
      "url": "http://localhost:5000",
      "pathMappings": [
        {
          "url": "webpack://foreman_openbolt/src",
          "path": "${workspaceFolder}/foreman_openbolt/webpack/src/"
        }
      ]
    }
  ]
}

The Attach to Ruby debugger configuration enables debugging of Ruby code while the Launch Firefox configuration enables debugging of the frontend code.

VS Code Run and Debug

Links

Clone this wiki locally