Ruby Logo

Debugging Tools

Debug Ruby and Rails applications with byebug, pry, the Ruby 3 debug gem, VS Code breakpoints, and remote sessions.

Home Ruby Debugging Tools

Debugging Tools for Ruby & Rails

Whether you are debugging a flaky test, a production regression, or a background job, Ruby offers a rich toolbox—byebug, pry, the Ruby 3+ debug gem, and IDE integrations. Learn when and how to use each.

Drop into breakpoints

byebug

`bundle exec byebug` injects a REPL into any Ruby process (including tests). Use commands like `next`, `step`, `break`, and `display` to inspect state.

pry

Drop `binding.pry` into code to get syntax-highlighted introspection, command history, and plugins like `pry-rails`, `pry-byebug`.

debug gem

Ruby 3.1+ ships with `debug` (`require 'debug'`). Adds record/replay, breakpoints via `rdbg`, and remote debugging sessions.

Rails console helpers

  • `rails console --sandbox` lets you explore behaviour without persisting data.
  • Enable logging with `ActiveRecord::Base.logger = Logger.new(STDOUT)` while you inspect queries.
  • Use `app.get '/ruby'` inside the console to replicate controller requests quickly.

Debugging background jobs & containers

# Remote debug with the `debug` gem bundle exec rdbg -n -O -- bin/rails runner "TrialReminderJob.perform_now" # Attach to a running container docker exec -it rubydev_web_1 rdbg -A --open # Sidekiq worker (inline) Sidekiq::Testing.inline! do binding.irb end

Remote sessions require open ports; ensure you tunnel securely (e.g., `ssh -L 12345:localhost:12345`). Always remove debug statements before committing.

Visual debugging

  • VS Code: install the Ruby extension, configure `launch.json` with `{ "command": "bundle exec rdbg --open -- bin/rails s" }` for server debugging.
  • RubyMine: run any spec or server with the debugger to inspect frames, locals, and evaluate expressions inline.
  • Use conditional breakpoints (`break if user.admin?`) to stop only when specific states occur.

Quick Navigation

Related Topics

Video Tutorial

Watch and learn debugging tools

Pro Tip: After reading through the content above, watch this video to reinforce your understanding and see the concepts in action!