RubyMine デバッグモード エラーになる

RubyMineでデバッグモードを起動する為に必要なgemをinstallしようとしてエラーが発生。
エラー発生から解決までを以下に記載します。

以下2つのgemのinstallを試みるもエラー発生。

```bash:command
sudo gem install ruby-debug-ide
sudo gem install debase
```

```terminal:terminal
yukiyoshimura /Applications/develop/workspace/railstest/db $ sudo gem install ruby-debug-ide
Building native extensions.  This could take a while...
ERROR:  Error installing ruby-debug-ide:
	ERROR: Failed to build gem native extension.
# エラーが発生

    current directory: /Users/yukiyoshimura/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/ruby-debug-ide-0.6.0/ext
/Users/yukiyoshimura/.rbenv/versions/2.2.3/bin/ruby mkrf_conf.rb
Installing base gem
Building native extensions.  This could take a while...
Building native extensions.  This could take a while...
ERROR: Failed to build gem native extension.

    current directory: /Users/yukiyoshimura/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/debase-0.2.2.beta10/ext
/Users/yukiyoshimura/.rbenv/versions/2.2.3/bin/ruby -r ./siteconf20170724-3553-1f15ajh.rb extconf.rb
checking for vm_core.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
	--with-opt-dir
	--without-opt-dir
	--with-opt-include
	--without-opt-include=${opt-dir}/include
	--with-opt-lib
	--without-opt-lib=${opt-dir}/lib
	--with-make-prog
	--without-make-prog
	--srcdir=.
	--curdir
	--ruby=/Users/yukiyoshimura/.rbenv/versions/2.2.3/bin/$(RUBY_BASE_NAME)
	--with-ruby-dir
	--without-ruby-dir
	--with-ruby-include=${ruby-dir}/include
	--with-ruby-lib
	--without-ruby-lib=${ruby-dir}/lib
/Users/yukiyoshimura/.rbenv/versions/2.2.3/lib/ruby/2.2.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
	from /Users/yukiyoshimura/.rbenv/versions/2.2.3/lib/ruby/2.2.0/mkmf.rb:587:in `try_cpp'
	from /Users/yukiyoshimura/.rbenv/versions/2.2.3/lib/ruby/2.2.0/mkmf.rb:1060:in `block in have_header'
	from /Users/yukiyoshimura/.rbenv/versions/2.2.3/lib/ruby/2.2.0/mkmf.rb:911:in `block in checking_for'
	from /Users/yukiyoshimura/.rbenv/versions/2.2.3/lib/ruby/2.2.0/mkmf.rb:351:in `block (2 levels) in postpone'
	from /Users/yukiyoshimura/.rbenv/versions/2.2.3/lib/ruby/2.2.0/mkmf.rb:321:in `open'
	from /Users/yukiyoshimura/.rbenv/versions/2.2.3/lib/ruby/2.2.0/mkmf.rb:351:in `block in postpone'
	from /Users/yukiyoshimura/.rbenv/versions/2.2.3/lib/ruby/2.2.0/mkmf.rb:321:in `open'
	from /Users/yukiyoshimura/.rbenv/versions/2.2.3/lib/ruby/2.2.0/mkmf.rb:347:in `postpone'
	from /Users/yukiyoshimura/.rbenv/versions/2.2.3/lib/ruby/2.2.0/mkmf.rb:910:in `checking_for'
	from /Users/yukiyoshimura/.rbenv/versions/2.2.3/lib/ruby/2.2.0/mkmf.rb:1059:in `have_header'
	from extconf.rb:31:in `block in <main>'
	from /Users/yukiyoshimura/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/debase-ruby_core_source-0.9.9/lib/debase/ruby_core_source.rb:15:in `call'
	from /Users/yukiyoshimura/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/debase-ruby_core_source-0.9.9/lib/debase/ruby_core_source.rb:15:in `create_makefile_with_core'
	from extconf.rb:47:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Users/yukiyoshimura/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-14/2.2.0-static/debase-0.2.2.beta10/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/yukiyoshimura/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/debase-0.2.2.beta10 for inspection.
Results logged to /Users/yukiyoshimura/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-14/2.2.0-static/debase-0.2.2.beta10/gem_make.out
/Users/yukiyoshimura/.rbenv/versions/2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/ext/builder.rb:92:in `run'
  /Users/yukiyoshimura/.rbenv/versions/2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/ext/ext_conf_builder.rb:48:in `block in build'
・
・
・
  mkrf_conf.rb:35:in `rescue in <main>'
  mkrf_conf.rb:28:in `<main>'

rake failed, exit code 1

Gem files will remain installed in /Users/yukiyoshimura/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/ruby-debug-ide-0.6.0 for inspection.
Results logged to /Users/yukiyoshimura/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-14/2.2.0-static/ruby-debug-ide-0.6.0/gem_make.out
```

詳細は

```/Users/yukiyoshimura/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-14/2.2.0-static/debase-0.2.2.beta10/mkmf.log
```
にと書いてるのでみてみる。
※mkmf.logのパスが出力されていない時は、gem_make.outが出力されているパスに行くとある。

```c:mkmf.log
You have not agreed to the Xcode license agreements, please run 'xcodebuild -license' (for user-level acceptance) or 'sudo xcodebuild -license' (for system-wide acceptance) from within a Terminal window to review and agree to the Xcode license agreements.
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return 0;
6: }
/* end */
```

logにある通りに```sudo xcodebuild -license```を実施。
※これ以外のケースもあり。mkmf.logの内容通りに素直に対応する。
すると最後に以下が表示されるのでagreeと打つ。

```bash:terminal
By typing 'agree' you are agreeing to the terms of the software license agreements. Type 'print' to print them or anything else to cancel, [agree, print, cancel]
```

gem installに再チャレンジして成功することを確認。

```bash:terminal
yukiyoshimura /Applications/develop/workspace/railstest $ sudo gem install ruby-debug-ide
Building native extensions.  This could take a while...
Successfully installed ruby-debug-ide-0.6.0
Parsing documentation for ruby-debug-ide-0.6.0
Installing ri documentation for ruby-debug-ide-0.6.0
Done installing documentation for ruby-debug-ide after 0 seconds
1 gem installed

#debaseもinstall
yukiyoshimura /Applications/develop/workspace/railstest $ sudo gem install debase
Password:
Building native extensions.  This could take a while...
Successfully installed debase-0.2.1
Parsing documentation for debase-0.2.1
Installing ri documentation for debase-0.2.1
Done installing documentation for debase after 0 seconds
1 gem installed

```

gem installがうまくいったので、rubymineからデバッグしてみる。
エラーがでた。

```terminal:ide
Fast Debugger (ruby-debug-ide 0.6.1.beta4, debase 0.2.2.beta10, file filtering is supported) listens on 0.0.0.0:51764
-e:1:in `sleep': Interrupt
```

debaseをversion 0.2.2.beta10で入れ直す

```bash:command
sudo gem uninstall debase
sudo gem install -v 0.2.2.beta10 debase
```

```bash:terminal
yukiyoshimura /Applications/develop/workspace/railstest2 $ sudo gem uninstall debase
Password:
Successfully uninstalled debase-0.2.1
yukiyoshimura /Applications/develop/workspace/railstest2 $ sudo gem install -v 0.2.2.beta10 debase
Building native extensions.  This could take a while...
Successfully installed debase-0.2.2.beta10
Parsing documentation for debase-0.2.2.beta10
Installing ri documentation for debase-0.2.2.beta10
Done installing documentation for debase after 0 seconds
1 gem installed
```

rubymineでdebugを再実行　→　成功:soccer:
※debugが動くけど、ブレークポイントで止まらないような不安定な動作をする時は、一度Rubymineを再起動するとうまくいくことがある。