CentOS6.3のrbenv(1.9.2p180)にdebuggerをインストールしてrailsを起動するまでのメモ

作業メモ。

Gemfileにdebuggerを追加。

source 'http://rubygems.org'
gem 'rails'

group :development, :test do
  gem 'debugger'
end

bundlerを実行すると、debuggerのインストールに失敗。

$ bundle install
~
Installing debugger (1.2.2) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /usr/local/rbenv/versions/1.9.2-p180/bin/ruby extconf.rb
checking for rb_method_entry_t.body in method.h... no
checking for vm_core.h... no
checking for rb_method_entry_t.body in method.h... no
checking for vm_core.h... no
Makefile creation failed
**************************************************************************
No source for ruby-1.9.2-p180 provided with debugger-ruby_core_source gem.
**************************************************************************
*** 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.
~

vm_core.hが見つからないので、Rubyのソースを指定してgemからインストール。

$ cd /usr/local/src
$ sudo wget http://core.ring.gr.jp/pub/lang/ruby/1.9/ruby-1.9.2-p180.tar.gz
$ sudo tar zxvf ruby-1.9.2-p180.tar.gz
$ gem install debugger -- -with-ruby-include=/usr/local/src/ruby-1.9.2-p180
Building native extensions.  This could take a while...
Successfully installed debugger-1.2.2
1 gem installed
Installing ri documentation for debugger-1.2.2...
Installing RDoc documentation for debugger-1.2.2...

bundler再実行で成功。

$ bundle install
~
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

Railsを起動するとdebuggerで例外発生。

$ rails s
/usr/local/rbenv/versions/1.9.2-p180/lib/ruby/gems/1.9.1/gems/debugger-1.2.2/lib/ruby-debug/interface.rb:55:in `block (2 levels) in initialize': uninitialized constant Debugger::LocalInterface::Readline (NameError)
        from /usr/local/rbenv/versions/1.9.2-p180/lib/ruby/gems/1.9.1/gems/debugger-1.2.2/lib/ruby-debug/interface.rb:53:in `each'
        from /usr/local/rbenv/versions/1.9.2-p180/lib/ruby/gems/1.9.1/gems/debugger-1.2.2/lib/ruby-debug/interface.rb:53:in `block in initialize'
        from /usr/local/rbenv/versions/1.9.2-p180/lib/ruby/gems/1.9.1/gems/debugger-1.2.2/lib/ruby-debug/interface.rb:52:in `open'
        from /usr/local/rbenv/versions/1.9.2-p180/lib/ruby/gems/1.9.1/gems/debugger-1.2.2/lib/ruby-debug/interface.rb:52:in `initialize'
        from /usr/local/rbenv/versions/1.9.2-p180/lib/ruby/gems/1.9.1/gems/debugger-1.2.2/lib/ruby-debug/processor.rb:61:in `new'
        from /usr/local/rbenv/versions/1.9.2-p180/lib/ruby/gems/1.9.1/gems/debugger-1.2.2/lib/ruby-debug/processor.rb:61:in `initialize'
        from /usr/local/rbenv/versions/1.9.2-p180/lib/ruby/gems/1.9.1/gems/debugger-1.2.2/lib/ruby-debug.rb:9:in `new'
        from /usr/local/rbenv/versions/1.9.2-p180/lib/ruby/gems/1.9.1/gems/debugger-1.2.2/lib/ruby-debug.rb:9:in `<module:Debugger>'
        from /usr/local/rbenv/versions/1.9.2-p180/lib/ruby/gems/1.9.1/gems/debugger-1.2.2/lib/ruby-debug.rb:8:in `<top (required)>'
        from /usr/local/rbenv/versions/1.9.2-p180/lib/ruby/gems/1.9.1/gems/debugger-1.2.2/lib/debugger.rb:4:in `require'
        from /usr/local/rbenv/versions/1.9.2-p180/lib/ruby/gems/1.9.1/gems/debugger-1.2.2/lib/debugger.rb:4:in `<top (required)>'
        ~

readline-develをインストールして、Rubyを再インストール。

$ sudo -i yum -y install readline-devel
$ sudo -i CONFIGURE_OPTS="--with-readline-dir=/usr/include/readline" rbenv install 1.9.2-p180

Raisを再起動。

$ rails s
=> Booting WEBrick
=> Rails 3.0.4 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2012-11-30 11:37:27] INFO  WEBrick 1.3.1
[2012-11-30 11:37:27] INFO  ruby 1.9.2 (2011-02-18) [x86_64-linux]
[2012-11-30 11:37:27] INFO  WEBrick::HTTPServer#start: pid=11569 port=3000