How to use Byebug to debug Ruby code

With Ruby 2.0 (and later), use the byebug gem to debug your code:
        gem install byebug
(Note version 1.X of Ruby used ruby-debug, but that library no longer works.)

To debug a particular Ruby program add

        require 'byebug'
at the top of the program and call
        byebug
wherever you'd like the application to "break" - that is, executing byebug is equivalent to putting a breakpoint in your code. Run the program and use the debugger commands once you reach the breakpoint.

  • For Rails applications, edit config/environments/development.rb and add the line
            require 'byebug'
    
    near the end. Restart your server. You can then add byebug statements to your Rails code. The server will enter the debugger shell and you can use the commands.

    Debugger Commands

    You're supposed to be able to get a list of debugger commands by typing help at the prompt, but this doesn't seem to be working. See the cheetsheet for a list of commands. The most common commands are Note that most commands come in a long and short form; for instance, list does the same as l.