Gem Install Debugger Error

梦想的初衷 提交于 2019-11-28 08:09:11

Ruby 2.1.2 isn't supported by debugger, unfortunately. Instead, use the byebug gem. See this discussion for more details.

Ruby 2.x is not supported by the debugger gem and you should use byebug instead. Once Rails 4.2.0 is released (or if you use the Rails 4.2.0rc versions) byebug will be the default debugger included in your Gemfile, but if you're on an earlier version of Rails then you'll need to make the change manually in your Gemfile.

Just replace

gem "debugger"

with

gem "byebug"

in your Gemfile and run a bundle install.

Some more background

Even the maintainer of the debugger gem makes this recommendation. The debugger gem's README on GitHub has the following note:

  • Only 1.9.2 and 1.9.3 are supported. For 2.X rubies, consider using byebug.

The maintainer has no intention of fixing this; he closed the issue debugger can't be installed on ruby 2.X unfixed, explaining that debugger never properly supported Ruby 2.X and that he now recommends byebug.

Additionally, the maintainer of debugger has not pushed a commit or even replied to a pull request since June 2014. The gem seems to be abandonware at this point.

Rails itself has adopted byebug as the official debugger for Ruby 2.X as of this pull request in April, and from Rails 4.2.0 onwards the Gemfile created when you run rails new my_new_app_name will reference byebug instead of debugger for Ruby 2.X users.

tl;dr

debugger is dead. Use byebug.

This monstrosity of a command ended up doing the trick for me:

gem install debugger-ruby_core_source && ARCHFLAGS="-I$(dirname -- "$(gem which debugger/ruby_core_source/ruby-$(ruby -v | awk '{sub(/p/, "-p", $2); print $2}')/vm_core.h)") -include vm_core.h" bundle install

My apologies.

Breaking it down:

  • First, install the Ruby headers.

    gem install debugger-ruby_core_source
    
  • Now, if that succeeds we want to run bundle install but it needs to be able to find those Ruby headers. Grepping the output of gem contents debugger-rebuy_core_source, we find that it installs a bunch of different headers for different patchlevels of Ruby:

    $ gem contents debugger-ruby_core_source | grep vm_core.h
    /Users/andrew/.gem/ruby/2.0.0/gems/debugger-ruby_core_source-1.3.2/lib/debugger/ruby_core_source/ruby-1.9.2-p290/vm_core.h
    /Users/andrew/.gem/ruby/2.0.0/gems/debugger-ruby_core_source-1.3.2/lib/debugger/ruby_core_source/ruby-1.9.2-p318/vm_core.h
    /Users/andrew/.gem/ruby/2.0.0/gems/debugger-ruby_core_source-1.3.2/lib/debugger/ruby_core_source/ruby-1.9.2-p320/vm_core.h
    ...
    
  • What’s the current patch level?

    $ ruby -v
    ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14]
    

    To transform that into the ruby-2.0.0-p318 format used by the debugger-ruby_core_source gem, we use awk to print only the second field of that version string, and change the p to -p:

    $ ruby -v | awk '{sub(/p/, "-p", $2); print $2}'
    2.0.0-p481
    
  • Now we run bundle install, with ARCHFLAGS set to add the directory containing the ruby headers to the include file search path, and preload vm_core.h:

    gem install debugger-ruby_core_source \
      && ARCHFLAGS="-I$(dirname -- \
        "$(gem which debugger/ruby_core_source/ruby-$(ruby -v | awk '{sub(/p/, "-p", $2); print $2}')/vm_core.h)") \
        -include vm_core.h" \
    bundle install
    

    i.e.,

    gem install debugger-ruby_core_source \
      && ARCHFLAGS="-I<path-to-dir_containing_vm_core.h> -include vm_core.h" \
        bundle install
    

For those who's using gem 'pry-debugger' just change it to gem 'pry-byebug' in your Gemfile.

Unfortunatelly no answer solved this problem. As answered before by nickh, "Ruby 2.1.2 isn't supported by debugger".

I found a japanese post that allowed me to install this gem, but i don't take any responsibility for it, since it's not an official release. Do it at your own risk:

git clone https://github.com/mekishizufu/debugger.git
cd debugger
git checkout ca451a9bdf
gem build debugger.gemspec
gem install debugger-1.6.6.gem

Source: http://d.hatena.ne.jp/mabots/20140723/1406087504

**Step 1**
gilchristiano@rails-intro:~/workspace (master) $ rails --version
Could not find debugger-1.6.6 in any of the sources
Run `bundle install` to install missing gems.
**Step 2**
gilchristiano@rails-intro:~/workspace (master) $ debugger-1.6.6
bash: debugger-1.6.6: command not found
**Step 3**
gilchristiano@rails-intro:~/workspace (master) $ gem install debugger -v '1.6.6'
Building native extensions.  This could take a while...
Successfully installed debugger-1.6.6
1 gem installed
**Step 4**
gilchristiano@rails-intro:~/workspace (master) $ bundle install
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!