LoginSignup
2
0

More than 3 years have passed since last update.

rails c がLoadErrorになった時の解消法

Posted at

現象

railsで開発をしていて、rails c,rails consoleを打った時に何故か以下のエラーが。

dlopen( ~/.rbenv/versions/2.5.0/lib/ruby/2.5.0/x86_64-darwin17/readline.bundle, 9): Library not loaded: /usr/local/opt/readline/lib/libreadline.7.dylib (LoadError)
  Referenced from: ~/.rbenv/versions/2.5.0/lib/ruby/2.5.0/x86_64-darwin17/readline.bundle
  Reason: image not found - ~/.rbenv/versions/2.5.0/lib/ruby/2.5.0/x86_64-darwin17/readline.bundle

対応

Gemfileにgem 'rb-readline' を追加してインストールすれば治る模様。
以下参考になりました
rails consoleでreadline(LoadError)が出た場合の対処
rails consoleコマンドがLoadErrorでエラーになったときの解消法

Gemfileの編集

Gemfile
~
gem 'rb-readline'
~

インストール

$ bundle install

再度実行

$ rails c

無事成功。

Loading development environment (Rails 5.1.6)
irb(main):001:0> 

原因

Homebrewにインストールされていたreadlineを更新しちゃったことが原因っぽい。
以下の記事が参考になりました。
Rails consoleがreadlineの原因でうまく読み込めなかった

$ brew info readline
/usr/local/Cellar/readline/7.0.3_1 (46 files, 1.5MB)
  Poured from bottle on 2018-05-19 at 14:48:10
/usr/local/Cellar/readline/8.0.0_1 (48 files, 1.5MB)
  Poured from bottle on 2019-06-06 at 21:32:09

前のバージョンに戻しても上手くいくようです。

$ brew switch readline 7.0.3_1
Cleaning /usr/local/Cellar/readline/8.0.0_1
Cleaning /usr/local/Cellar/readline/7.0.3_1
Opt link created for /usr/local/Cellar/readline/7.0.3_1

再度実行して成功。

$ rails c
Running via Spring preloader in process 584
Loading development environment (Rails 5.1.6)
irb(main):001:0>
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0