この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。
こんにちは、虎塚です。
Amazon Linux上でRubyのスクリプトを実行しようとした時に、bundlerが動かないことがあります。今回はその場合の対処法を記述します。
環境
- AMI: amzn-ami-hvm-2015.03.0.x86_64-gp2 (ami-cbf90ecb)
- カーネル: 3.14.48-33.39.amzn1.x86_64
- ruby 2.0.0p645 (2015-04-13) [x86_64-linux]
現象
Amazon LinuxにSSHログインして、任意のディレクトリにGemfileを用意し、bundle installを実行します。この時、次のようなエラーが出る場合があります。
$ bundle install
/usr/share/ruby/vendor_ruby/2.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- io/console (LoadError)
from /usr/share/ruby/vendor_ruby/2.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /home/ec2-user/.gem/ruby/2.0/gems/bundler-1.10.6/lib/bundler/vendor/thor/lib/thor/shell/basic.rb:2:in `<top (required)>'
from /usr/share/ruby/vendor_ruby/2.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/share/ruby/vendor_ruby/2.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /home/ec2-user/.gem/ruby/2.0/gems/bundler-1.10.6/lib/bundler/vendor/thor/lib/thor/shell/color.rb:1:in `<top (required)>'
from /home/ec2-user/.gem/ruby/2.0/gems/bundler-1.10.6/lib/bundler/vendor/thor/lib/thor/shell.rb:17:in `shell'
from /home/ec2-user/.gem/ruby/2.0/gems/bundler-1.10.6/lib/bundler/ui/shell.rb:14:in `initialize'
from /home/ec2-user/.gem/ruby/2.0/gems/bundler-1.10.6/lib/bundler/cli.rb:12:in `new'
from /home/ec2-user/.gem/ruby/2.0/gems/bundler-1.10.6/lib/bundler/cli.rb:12:in `rescue in start'
from /home/ec2-user/.gem/ruby/2.0/gems/bundler-1.10.6/lib/bundler/cli.rb:10:in `start'
from /home/ec2-user/.gem/ruby/2.0/gems/bundler-1.10.6/bin/bundle:20:in `block in <top (required)>'
from /home/ec2-user/.gem/ruby/2.0/gems/bundler-1.10.6/lib/bundler/friendly_errors.rb:7:in `with_friendly_errors'
from /home/ec2-user/.gem/ruby/2.0/gems/bundler-1.10.6/bin/bundle:18:in `<top (required)>'
from /home/ec2-user/bin/bundle:23:in `load'
from /home/ec2-user/bin/bundle:23:in `<main>'
対処法
エラーメッセージにしたがって、io-consoleをインストールします。
このとき、次のようなエラーが出て、インストールに失敗するかもしれません。
$ gem install io-console
Fetching: io-console-0.4.2.gem (100%)
Building native extensions. This could take a while...
ERROR: Error installing io-console:
ERROR: Failed to build gem native extension.
/usr/bin/ruby2.0 extconf.rb
mkmf.rb can't find header files for ruby at /usr/share/ruby/include/ruby.h
Gem files will remain installed in /home/ec2-user/.gem/ruby/2.0/gems/io-console-0.4.2 for inspection.
Results logged to /home/ec2-user/.gem/ruby/2.0/gems/io-console-0.4.2/./gem_make.out
これは、Module: MakeMakefile (Ruby 2.0.0)が必要とするruby.hが、Amazon Linuxに初期インストールされていないためです。
上記のエラーが出た場合は、先にruby-develをインストールします。
$ sudo yum install ruby-devel
これで、io-consoleをインストールできます。
$ gem install io-console
Building native extensions. This could take a while...
Successfully installed io-console-0.4.2
Parsing documentation for io-console-0.4.2
Installing ri documentation for io-console-0.4.2
Done installing documentation for io-console after 0 seconds
1 gem installed
以上で、bundle installが成功するようになります。
それでは、また。