Dirk Bergmann

Developer, panographer. Does consultancy work from own company. Lives in Chiang Mai, Thailand.


Chiang Mai

Hua Hin

Thailand Hotels

ListVote - List. Vote. Learn.

Partnerseek - Find Partners

ruby-debug with Ruby 1.9.x and Rails 3 on RVM

Things are moving fast in the Rails/Ruby world with the imminent releases of Ruby 1.9.2 and Rails 3.

An essential tool for a smooth transition is RVM by Wayne Seguin (Where can i vote for this guy as Ruby Hero? Ah, it's here.)

In the first Rails 3 Railscast RVM sounds more like an afterthought and only necessary if you don't have Ruby 1.8.7+ installed, but it's advisable to not even try the migration to Rails 3 without installing RVM and a dedicated version of Ruby (can be the same version as your current system Ruby).

While taking the plunge with Rails 3 and its many breaking changes, why not go all the way in a twisted pun sort of way? As Ryan Bates recommends in Railscast 208, it may be time to skip Ruby 1.9.1 and install ruby-head on RVM, which is currently 1.9.2, expected to be released in a few months.

Once you have Rails 3 (currently Beta 3) and Ruby 1.9.2 installed on RVM, perhaps with this nifty script that includes the entire starting "gemset", you will find that the ruby-debug gem can't be installed on Ruby 1.9.x, the installer will tell you

Can't handle 1.9.x yet

and other stuff.

Don't despair Mark Moseley has created all the necessary gems for you. You can install the ruby 1.9.1 and 1.9.2. compatible debugger and the debug ide with the following commands (thanks to Wayne's exemplary documentation):

gem install ruby-debug19 -- --with-ruby-include=$rvm_path/src/ruby-head/

gem install ruby-debug-ide19 -- --with-ruby-include=$rvm_path/src/ruby-head/

Now when you run

rails server --debugger

it still won't be working, saying

"You need to install ruby-debug to run the server in debugging mode."

So, as the last step, put this in your Gemfile

gem 'ruby-debug19', :require => 'ruby-debug'

Run 'bundle install' if you feel like it, and now the debugger should work. However, the debugger will now start every time you start the server.

To start the server without the debugger, you'll have to uncomment the line above in the Gemfile again.

Anyone with a workaround for this please post in the comments.

Hope it helps.

P.S. Don't forget to give back to Open Source!


mooman: totally awesome and helped me out so much!! thank you!!

Bruno Grasselli: It worked pretty well for me on linux, but not on mac os x. This command works on both (from rvm documentation): gem install ruby-debug19 -- --with-ruby-include="$rvm_src_path/$(rvm tools identifier)/" Thanks for the tip!

peetucket: Thanks - saved me from pulling some hair out.

rubyconvict: Thanks Bruno, your one-liner works on ubuntu with rvm.

brownman: now i'm absolutly happy :) thanks man !

Leonardo Daronco: Thanks, it helped a lot! I had some trouble installing ruby-debug19 using bundler. The installation of linecache19 and ruby-debug-base19 was stalling while building the gems with native extensions. But using "gem install --with-ruby-include" the installation was ok. The solution was to the following lines to ".bundle/config": BUNDLE_BUILD__LINECACHE19: --with-ruby-include=$rvm_path/src/$(rvm tools identifier)/ BUNDLE_BUILD__RUBY-DEBUG-BASE19: --with-ruby-include=$rvm_path/src/$(rvm tools identifier)/

Cristobal Viedma: thanks for the post! just a quicky: it's: rails server --debugger (with double dash). took me a few minutes... ;)

Anocha: Great post. To get around comment/un-comment the line gem ?ruby-debug19?, :require => ?ruby-debug? simply put it in a group, which you can later request or ignore when you run bundle install. See the last example, of this post. http://gembundler.com/gemfile.html

postmodern: You can use Ruby 1.9's built-in debugger: require 'debug' Or via the command-line: $ ruby -rdebug test.rb

Nic: Thanks, very helpful.

Brendan Boesen: By the way, for those copying these lines, the first dash following the colon should actually be two hyphens, i.e.: BUNDLE_BUILD__LINECACHE19: [hyphen][hyphen] [hyphen][hyphen]with-ruby-etc. (I pasted in two hyphens but this blog's software turns them into some funny double-width hyphen character like Word does)

Brendan Boesen: Using rvm tools identifier doesn't work when you're using a gemset. The following seems to work ok for a .bundle/config: BUNDLE_BUILD__LINECACHE19: -- --with-ruby-include="$rvm_path/src/$(rvm tools identifier | cut -d '@' -f1)" BUNDLE_BUILD__RUBY-DEBUG-BASE19: -- --with-ruby-include="$rvm_path/src/$(rvm tools identifier | cut -d '@' -f1)"

vidur punj: Many many thanks to you..