pry起動時に「Sorry, you can't use Pry without Readline or a compatible library.」と言われる場合あるいはirbで矢印キーが動かない場合
irbで矢印キーを入力するとエスケープ文字が出力されてしまったり、pryを移動させるとエラーになってしまう場合の対処。
OSのバージョンをSierraにしたからか、irbやpryがうまく動かなくなってしまった。
# bundle exec pry Sorry, you can't use Pry without Readline or a compatible library. Possible solutions: * Rebuild Ruby with Readline support using `--with-readline` * Use the rb-readline gem, which is a pure-Ruby port of Readline * Use the pry-coolline gem, a pure-ruby alternative to Readline bundler: failed to load command: pry (/private/tmp/hoge/vendor/bundle/bin/pry) LoadError: dlopen(/Users/sugamasao/.rbenv/versions/2.3.1/lib/ruby/2.3.0/x86_64-darwin15/readline.bundle, 9): Library not loaded: /usr/local/opt/readline/lib/libreadline.6.dylib Referenced from: /Users/sugamasao/.rbenv/versions/2.3.1/lib/ruby/2.3.0/x86_64-darwin15/readline.bundle Reason: image not found - /Users/sugamasao/.rbenv/versions/2.3.1/lib/ruby/2.3.0/x86_64-darwin15/readline.bundle /private/tmp/hoge/vendor/bundle/gems/pry-0.10.4/lib/pry/config/default.rb:151:in `require' /private/tmp/hoge/vendor/bundle/gems/pry-0.10.4/lib/pry/config/default.rb:151:in `lazy_readline' /private/tmp/hoge/vendor/bundle/gems/pry-0.10.4/lib/pry/config/default.rb:6:in `block in <class:Default>' /private/tmp/hoge/vendor/bundle/gems/pry-0.10.4/lib/pry/config/default.rb:125:in `instance_eval' /private/tmp/hoge/vendor/bundle/gems/pry-0.10.4/lib/pry/config/default.rb:125:in `block (2 levels) in <class:Default>' /private/tmp/hoge/vendor/bundle/gems/pry-0.10.4/lib/pry/config/behavior.rb:54:in `public_send' /private/tmp/hoge/vendor/bundle/gems/pry-0.10.4/lib/pry/config/behavior.rb:54:in `method_missing' /private/tmp/hoge/vendor/bundle/gems/pry-0.10.4/lib/pry/history.rb:19:in `restore_default_behavior' /private/tmp/hoge/vendor/bundle/gems/pry-0.10.4/lib/pry/history.rb:14:in `initialize' /private/tmp/hoge/vendor/bundle/gems/pry-0.10.4/lib/pry/pry_class.rb:33:in `new' /private/tmp/hoge/vendor/bundle/gems/pry-0.10.4/lib/pry/pry_class.rb:33:in `history' /private/tmp/hoge/vendor/bundle/gems/pry-0.10.4/lib/pry/pry_class.rb:222:in `load_history' /private/tmp/hoge/vendor/bundle/gems/pry-0.10.4/lib/pry/pry_class.rb:129:in `initial_session_setup' /private/tmp/hoge/vendor/bundle/gems/pry-0.10.4/lib/pry/cli.rb:206:in `block in <top (required)>' /private/tmp/hoge/vendor/bundle/gems/pry-0.10.4/lib/pry/cli.rb:83:in `block in parse_options' /private/tmp/hoge/vendor/bundle/gems/pry-0.10.4/lib/pry/cli.rb:83:in `each' /private/tmp/hoge/vendor/bundle/gems/pry-0.10.4/lib/pry/cli.rb:83:in `parse_options' /private/tmp/hoge/vendor/bundle/gems/pry-0.10.4/bin/pry:16:in `<top (required)>' /private/tmp/hoge/vendor/bundle/bin/pry:23:in `load' /private/tmp/hoge/vendor/bundle/bin/pry:23:in `<top (required)>'
調べてみると、どうも readline
がおかしいらしい。
readlineを入れ直す
複数バージョン入っていたので一度全て消してインストール
$ brew uninstall readline Uninstalling /usr/local/Cellar/readline/7.0... (45 files, 2M) readline 6.3.5, 6.3.8 are still installed. Remove all versions with `brew uninstall --force readline`. $ brew uninstall --force readline Uninstalling readline... (92 files, 4M) $ brew install readline ==> Auto-updated Homebrew! Updated 2 taps (homebrew/core, homebrew/science).
Rubyを入れ直す
rbenvなのでrbenvでuninstallしてinstallする
$ rbenv uninstall 2.3.1 rbenv: remove /Users/sugamasao/.rbenv/versions/2.3.1? y $ rbenv install 2.3.1
これでpryを起動したりするとうまく動くようになった。やったー