IntelliJでWSLのrubyをデバッグする

概要

WSLでインストールしたubunturubyをインストールする。
rubyのバージョン管理はrbenvを利用する。

rbenv

  • bash_profile設定
$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
$ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
  • 必要パッケージ
$ sudo apt install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm5 libgdbm-dev
  • bash_profile 設定
# rbenv
if [ -e $HOME/.rbenv ]; then
    export PATH="$HOME/.rbenv/bin:$PATH"
fi
 
  • 特定バージョンruby インストール
$ rbenv install 2.6.1
 

InltelliJ 設定

IntelliJRuby開発プロジェクトを設定する。
 
プラグインからRubyをインストール
 
Project設定
プロジェクトにRuby SDKを設定する。
左は新規プロジェクト、右は既存プロジェクト
  • WSL、Ubuntu を選択する。
  • Ruby or …はUbuntuにインストールしたrbenvの利用したいバージョンのrubyを指定する
  • /home/gyamin/.rbenv/versions/2.6.1/bin/ruby
 
Run/Debug設定
IntelliJからプログラム実行やデバッグを行うには、Run/Debugを設定する。SDKとして上記で設定したRubyを指定する。
Debugを開始すると、Debugに必要なGemがインストールされる。
正常にインストールできれば、エディタで設定したブレークポイントデバッグができるようになる。