rails cが起動しないトラブルシュート

## 環境

Ubuntu20.4
Ruby2.6
Rails5.2

## はじめに

**rails c**をしたところ次のようなエラーが大量に出ました。この事象のトラブルシュートです。

```
$rails c
Traceback (most recent call last):
        37: from -e:1:in `<main>'
        36: from /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        35: from /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        34: from /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:285:in `load'
        33: from /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:257:in `load_dependency'
        32: from /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:285:in `block in load'
        31: from /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:285:in `load'
        30: from /vagrant/raku_renkei/bin/rails:9:in `<main>'
        29: from /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `require'
        28: from /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:257:in `load_dependency'
        27: from /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `block in require'
        26: from /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
        25: from /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
        24: from /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/railties-5.2.8.1/lib/rails/commands.rb:18:in `<main>'
        23: from /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/railties-5.2.8.1/lib/rails/command.rb:44:in `invoke'
        22: from /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/railties-5.2.8.1/lib/rails/command.rb:70:in `find_by_namespace'
        21: from /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/railties-5.2.8.1/lib/rails/command/behavior.rb:79:in `lookup'
        20: from /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/railties-5.2.8.1/lib/rails/command/behavior.rb:79:in `each'
        19: from /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/railties-5.2.8.1/lib/rails/command/behavior.rb:80:in `block in lookup'
        18: from /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/railties-5.2.8.1/lib/rails/command/behavior.rb:80:in `each'
        17: from /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/railties-5.2.8.1/lib/rails/command/behavior.rb:84:in `block (2 levels) in lookup'
        16: from /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `require'
        15: from /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:257:in `load_dependency'
        14: from /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `block in require'
        13: from /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
        12: from /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
        11: from /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/railties-5.2.8.1/lib/rails/commands/console/console_command.rb:4:in `<main>'
        10: from /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `require'
         9: from /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:257:in `load_dependency'
         8: from /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `block in require'
         7: from /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
         6: from /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
         5: from /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/2.6.0/irb/completion.rb:10:in `<main>'
         4: from /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `require'
         3: from /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:257:in `load_dependency'
         2: from /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `block in require'
         1: from /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/home/vagrant/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require': cannot load such file -- /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/2.6.0/x86_64-linux/readline.so (LoadError)

```

どうも多くのgemでエラーが出ているようです。rails sは正常に動いているため、恐らくgem自体の問題ではなさそうです。ポイントになるのは最終行のエラーだろうと目星を付けました。readline.soが本当にないのか検索してみたところ、確かに存在していませんでした。

```
cannot load such file -- /home/vagrant/.rbenv/versions/2.6.0/lib/ruby/2.6.0/x86_64-linux/readline.so (LoadError)
```

## やったこと

**readline**というLinuxのライブラリがないことが原因のようです。**readline**をインストールすれば解決すると思われますが、代わりに、**rb-readline**というgemで対応ができるようです。readlineライブラリがなくても動作できる、Ruby専用のreadlineという位置づけのようです。

#### Gemfileに記述します。

```Gemfile
gem 'rb-readline'
```

#### インストールします。

```
$bundel install
```

#### 動作確認

うまく動作されるようになりました。

```
$rails c
Running via Spring preloader in process 3575
Loading development environment (Rails 5.2.8.1)
[1] pry(main)>
```

## 参考

こちらの情報を参考にさせてもらいました。

https://qiita.com/roki1801/items/7e4a371ae0b9ba928f55