28
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

rails consoleコマンドがLoadErrorでエラーになったときの解消法

Last updated at Posted at 2015-03-04

1. 概要

Railsアプリケーションとコマンドラインでやり取りをするためのコマンドである、
$ rails console 
$ rails c(短縮形)
が、正常に動かなかったので、対処法を書きます。

2. rails consoleの実行

まず、なにもしていない状態で、$ rails console を実行してみます。

$ rails console 

実行結果
/home/vagrant/.rbenv/versions/2.1.3/lib/ruby/2.1.0/irb/completion.rb:9:in `require': cannot load such file -- readline (LoadError) from /home/vagrant/.rbenv/versions/2.1.3/lib/ruby/2.1.0/irb/completion.rb:9:in `<top (required)>' from /home/vagrant/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/railties-4.1.8/lib/rails/commands/console.rb:3:in `require' from /home/vagrant/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/railties-4.1.8/lib/rails/commands/console.rb:3:in `<top (required)>' from /home/vagrant/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:128:in `require' from /home/vagrant/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:128:in `require_command!' from /home/vagrant/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:59:in `console' from /home/vagrant/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:40:in `run_command!' from /home/vagrant/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/railties-4.1.8/lib/rails/commands.rb:17:in `<top (required)>' from bin/rails:4:in `require' from bin/rails:4:in `<main>'

このようにエラー(LoadError)となり、コマンドラインが開きません。

記載のエラー内に、
/home/vagrant/.rbenv/versions/2.1.3/lib/ruby/2.1.0/irb/completion.rb:9:in `require': cannot load such file -- readline (LoadError)
とあります。

どうやら、readline というものがないといけないようです。

3. rb-readlineをgemで追加

エラーを解消するために、rb-readline をインストールします。

Gemfilerb-readline を追記し、bundle install でインストール

Gemfile 追加記述
gem 'rb-readline'

インストール実行
$ bundle install

実行結果

//rubygems.org/..........
Fetching version metadata from https://rubygems.org/..
Resolving dependencies...
Using rake 10.4.2
Using i18n 0.7.0
Using json 1.8.2
Using minitest 5.5.1
Using thread_safe 0.3.4
Using tzinfo 1.2.2
Using activesupport 4.1.8
Using builder 3.2.2
Using erubis 2.7.0
Using actionview 4.1.8
Using rack 1.5.2
Using rack-test 0.6.3
Using actionpack 4.1.8
Using mime-types 2.4.3
Using mail 2.6.3
Using actionmailer 4.1.8
Using activemodel 4.1.8
Using arel 5.0.1.20140414130214
Using activerecord 4.1.8
Using bundler 1.8.3
Using coffee-script-source 1.9.1
Using execjs 2.3.0
Using coffee-script 2.3.0
Using thor 0.19.1
Using railties 4.1.8
Using coffee-rails 4.0.1
Using hike 1.2.3
Using multi_json 1.10.1
Using jbuilder 2.2.9
Using jquery-rails 3.1.2
Using libv8 3.16.14.7
Using tilt 1.4.1
Using sprockets 2.12.3
Using sprockets-rails 2.2.4
Using rails 4.1.8
Installing rb-readline 0.5.2
Using rdoc 4.2.0
Using ref 1.0.5
Using sass 3.2.19
Using sass-rails 4.0.5
Using sdoc 0.4.1
Using spring 1.3.3
Using sqlite3 1.3.10
Using therubyracer 0.12.1
Using turbolinks 2.5.3
Using uglifier 2.7.1
Bundle complete! 12 Gemfile dependencies, 46 gems now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.```

# 4. rails consoleの再実行
再び、`$ rails console` を実行してみます。

`$ rails console` 
> **実行結果**
```Loading development environment (Rails 4.1.8)
irb(main):001:0> ```

無事にコマンドラインが開きました。
28
13
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
28
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?