20
[ec2-user@ip-XX-XXX-XXX-XXX rails]$ rails -h
/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 /usr/local/share/ruby/gems/2.0/gems/thor-0.19.1/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 /usr/local/share/ruby/gems/2.0/gems/thor-0.19.1/lib/thor/shell/color.rb:1:in `<top (required)>'
    from /usr/local/share/ruby/gems/2.0/gems/thor-0.19.1/lib/thor/shell.rb:17:in `shell'
    from /usr/local/share/ruby/gems/2.0/gems/thor-0.19.1/lib/thor/base.rb:439:in `start'
    from /usr/local/share/ruby/gems/2.0/gems/railties-4.1.0/lib/rails/commands/application.rb:17: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 /usr/local/share/ruby/gems/2.0/gems/railties-4.1.0/lib/rails/cli.rb:14: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 /usr/local/share/ruby/gems/2.0/gems/railties-4.1.0/bin/rails:9:in `<top (required)>'
    from /usr/local/bin/rails:23:in `load'
    from /usr/local/bin/rails:23:in `<main>'

I did install Ruby on Rails using $ gem install rails and it completed fine as well. I had checked the process status with $echo $? and it was 0 meaning successful.

Interestingly these two commands work fine:

$ which rails
/usr/local/bin/rails

$ rails -v
Rails 4.1.0

This is a Amazon Web Services AMI image 64 bit. Please help me figure this out.

I have the bundler installed:

$ gem install bundler
Fetching: bundler-1.6.2.gem (100%)
Successfully installed bundler-1.6.2
Parsing documentation for bundler-1.6.2
Installing ri documentation for bundler-1.6.2
Done installing documentation for bundler after 5 seconds
1 gem installed

I checked for duplicate installs:

$ find / 2>/dev/null| grep bin/ruby
/usr/bin/ruby
/usr/bin/ruby2.0

$ find / 2>/dev/null| grep bin/rails
/usr/local/share/ruby/gems/2.0/gems/railties-4.1.0/bin/rails
/usr/local/share/ruby/gems/2.0/gems/railties-4.1.0/lib/rails/generators/rails/plugin/templates/bin/rails.tt
/usr/local/share/ruby/gems/2.0/gems/railties-4.1.0/lib/rails/generators/rails/app/templates/bin/rails
/usr/local/share/ruby/gems/2.0/gems/rails-4.1.0/guides/code/getting_started/bin/rails
/usr/local/bin/rails
/home/ec2-user/.gem/ruby/2.0/gems/rails-4.1.0/guides/code/getting_started/bin/rails
janfoeh
  • 10,243
  • 2
  • 31
  • 56
gvermag
  • 389
  • 1
  • 5
  • 12

4 Answers4

23

You would need to install io-console gem. Install it using following command:

gem install io-console

After this run rails -h

Also, run echo $PATH and make sure that you have /usr/local/bin in the path. If not, then you would need to add it.

Kirti Thorat
  • 52,578
  • 9
  • 101
  • 108
  • 2
    I'm a complete rails newb and I had the same problem as the OP. when I try to do install the io-console gem I get: `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` wth? – Dave Munger Apr 30 '14 at 16:35
  • 2
    Checkout these SO answers: [gem install: Failed to build gem native extension (can't find header files)](http://stackoverflow.com/questions/4304438/gem-install-failed-to-build-gem-native-extension-cant-find-header-files) and [Error while installing json gem 'mkmf.rb can't find header files for ruby'](http://stackoverflow.com/questions/20559255/error-while-installing-json-gem-mkmf-rb-cant-find-header-files-for-ruby) as your problem seems related to these. – Kirti Thorat Apr 30 '14 at 16:54
  • Thanks! It actually turned out to be directory permissions that I had fubared pretty badly. I killed the instance I had messed up and launched a new one, and this time this solution worked for me. – Dave Munger May 01 '14 at 18:15
  • 1
    @DaveMunger Thats great! Glad my answer helped in some way. – Kirti Thorat May 01 '14 at 18:20
  • I'd like to add for everyone who's using AWS and facing this problem, this properly solves it instead of the accepted answer. – He Hui Dec 02 '15 at 09:11
9

So I had resolved this the same night, but somehow Stackoverflow didnt send me any notifications on the responses to the question, so I didnt know of these responses. This is what I ended up doing. It was essentially removing the ruby on rails installation and installing it from scratch. This was on a Amazon Web services server - linux flavor.

sudo yum update

$wget  https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer

$ bash -s stable < rvm-installer

$ source /home/ec2-user/.rvm/scripts/rvm

$ rvm requirements

$ sudo yum erase ruby

$ rvm install ruby

$ rvm use ruby --default

$ rvm rubygems current

$ gem install rails   # this takes forever

After that it worked just fine.

Tobias
  • 4,523
  • 2
  • 20
  • 40
gvermag
  • 389
  • 1
  • 5
  • 12
7

I had exactly the same issue on AWS Elastic Beanstalk (Puma, Ruby 2, Rails 4.0):

> rails generate simple_form:install --bootstrap

/usr/local/share/ruby/gems/2.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require': cannot load such file -- io/console (LoadError)

I simply added:

gem 'io-console'

To the top of my Gemfile and ran bundle install again on the box for great success. Hopefully quicker than reinstalling rails for anyone else who runs in to this.

SR.
  • 341
  • 3
  • 8
  • 1
    I had a similar issue with `rails new myapp` on an amazon ec2 micro instance and did `gem install io-console` and that cleared it up – Mike Jun 18 '15 at 14:23
  • Still relevant for me today on fresh EC2 image. `gem install io-console` fixed it, no rails necessary. – Joe Atzberger May 06 '16 at 00:49
2

Thanks; you need io-console indeed. To make that work, install GCC. Rest is needed later on so:

yum -y install gcc mysql-devel ImageMagick-devel

Then,

gem install io-console

works and I could continue installing.

Nissa
  • 4,636
  • 8
  • 29
  • 37
klaas
  • 21
  • 1