Ruby 1.9.2 and Rails 3 cannot open rails console

22,601

Solution 1

Apparently ubuntu and ruby don't always catch dependencies like they should.

From the first google hit (yeah, I clicked on this stack-overflow in place #2 before checking out the first result.)

Navigate to the Ruby source and enter:

sudo apt-get install libreadline5-dev
cd ext/readline
ruby extconf.rb
make
sudo make install

So, if you're on another distro, make sure you install readline somehow (source/package), then run make/install on extconf from the source. I tried what gkaykck suggested of course but got this without readline already on my system.

$ ruby extconf.rb
checking for tgetnum() in -lncurses... no
checking for tgetnum() in -ltermcap... no
checking for tgetnum() in -lcurses... no
checking for readline/readline.h... no
checking for editline/readline.h... no

Solution 2

Recipe for those who use rvm:

rvm pkg install readline
rvm remove 1.9.3
rvm install 1.9.3 --with-readline-dir=$rvm_path/usr

In more details about it on https://rvm.io/packages/readline/

Solution 3

If you want another solution to this problem do this.

sudo apt-get install libreadline6

Then in your gem file add:

gem 'rb-readline'

Then

bundle install

And you should be all set.

Solution 4

I'd recommend using rvm (Ruby Version Manager) to manage your different versions of Ruby and switch between them. It does a pretty good job of compiling the various versions for you too. You can even create per-directory .rvmrc files to tell rvm what version of ruby to use in which directory (as well as use per-project gem sets if you want!)

Solution 5

First of all uninstall every ruby version you have.

After that display rvm requirements:

rvm requirements

You will get something like:

Requirements for Linux ( DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=11.10
DISTRIB_CODENAME=oneiric
DISTRIB_DESCRIPTION="Ubuntu 11.10" )

NOTE: 'ruby' represents Matz's Ruby Interpreter (MRI) (1.8.X, 1.9.X)   
This is the *original* / standard Ruby Language Interpreter  
      'ree'  represents Ruby Enterprise Edition  
      'rbx'  represents Rubinius  

bash >= 4.1 required curl is required git is required (>= 1.7 for
ruby-head) patch is required (for 1.8 rubies and some ruby-head's).

To install rbx and/or Ruby 1.9 head (MRI) (eg. 1.9.2-head), then you
must install and use rvm 1.8.7 first.

Additional Dependencies: 
# For Ruby / Ruby HEAD (MRI, Rubinius, & REE), install the following:
  ruby: /usr/bin/apt-get install build-essential openssl libreadline6 
  libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev 
  libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev 
  ncurses-dev automake libtool bison subversion

# For JRuby, install the following:
  jruby: /usr/bin/apt-get install curl g++ openjdk-6-jre-headless
  jruby-head: /usr/bin/apt-get install ant openjdk-6-jdk

# For IronRuby, install the following:
  ironruby: /usr/bin/apt-get install curl mono-2.0-devel

Install all dependencies via apt-get.
After that install ruby 1.8.7. This version is required if you plan to use ruby 1.9.x
Now you can install ruby 1.9.3:

rvm pkg install readline
rvm remove 1.9.3
rvm install 1.9.3 --with-readline-dir=$rvm_path/usr

Note that you dont even need to install readline package via rvm if you had installed it using apt-get.

Share:
22,601

Related videos on Youtube

gkaykck
Author by

gkaykck

Updated on August 21, 2020

Comments

  • gkaykck
    gkaykck over 3 years
    [gkaykck@main myApplication]$ rails console
    /usr/local/lib/ruby/1.9.1/irb/completion.rb:9:in `require': no such file to load -- readline (LoadError)
        from /usr/local/lib/ruby/1.9.1/irb/completion.rb:9:in `<top (required)>'
        from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands/console.rb:3:in `require'
        from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands/console.rb:3:in `<top (required)>'
        from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands.rb:20:in `require'
        from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands.rb:20:in `<top (required)>'
        from script/rails:6:in `require'
        from script/rails:6:in `<main>'
    

    I have installed rails 3 on ruby 1.9.2p136, which is ok i guess. But i cannot start rails console and it gives me the error i copied. The apps worked great with ruby 1.8.7 and i never saw an error like this.

    Any ideas what it could be?

    • idlefingers
      idlefingers about 13 years
      How have you installed 1.9.2? You need to install readline first and compile ruby with readline support. Also, from the stacktrace, it looks like it's using 1.9.1...
    • fifigyuri
      fifigyuri about 13 years
      What happens when you type irb for 1.9.2? Can you require 'readline'?
    • gkaykck
      gkaykck about 13 years
      @idlefingers i installed 1.9.2 from source and if i ask for ruby -v it says "ruby 1.9.2p136 (2010-12-25 revision 30365) [i686-linux]". I don't know about readline but except irb everything works normally
    • gkaykck
      gkaykck about 13 years
      @fifigyuri no i cannot require readline, so i think problem is there
    • JJD
      JJD over 11 years
      Philippe's answer in a similar post worked for me: gem install rb-readline and add gem 'rb-readline' to your Gemfile.
    • H6.
      H6. over 10 years
      Found this: happy-coding.com/…
  • gkaykck
    gkaykck about 13 years
    i don't like using rvm neither using multiple ruby or rails versions or even any software's multiple versions at once, i don't think it CAN be a good practice.
  • mhmhmhmh
    mhmhmhmh about 13 years
    You don't need to install multiple versions of Ruby. Even if you only use one, it's worth switching to RVM.
  • fifigyuri
    fifigyuri about 13 years
    @gkaykck rvm saved me so much effort and time. It simplifies not only ruby version management, but also maintaining different gemsets for various ruby projects.
  • gkaykck
    gkaykck about 13 years
    ok i know that it simplifies things but, things should be simple, not simpler. Ruby and Rails means there will be really much things running under hood, and i want to see under the hood whenever possible with this kind of errors or stuff. Otherwise i'll only learn how to use rails and ruby, but i'll not learn ruby on rails in depth
  • zetetic
    zetetic about 13 years
    @gkaykck: Use RVM. Trust us on this one.
  • futuremint
    futuremint about 13 years
    @gkaykck RVM isn't some wicked voodoo magic or anything. Its basically just a command-line utility that does some path management for your installed rubies & gems. You can still go poking around your ruby installation, except its even easier to find because you'll find the whole ruby tree in ~/.rvm.
  • gkaykck
    gkaykck almost 13 years
    i moved to windows actually, but someone may find it helpful, thanks
  • Juanin
    Juanin over 12 years
    Thanks, it worked for me on Ubuntu 10.04 LTS + ruby 1.9.2-p180
  • winfred
    winfred over 12 years
    I would imagine that a production Ubuntu environment would exhibit similar behavior. It's always a good idea to run changes through a mock production/staging environment first.
  • DiveInto
    DiveInto over 12 years
    if you use rvm,find ruby src under:~/.rvm/src/ruby-version-number/ext/readline
  • Tass
    Tass over 12 years
    Concur, RVM is great. I've needed to use different versions of ruby and this has been very valuable. I know how you feel about ruby, I also want to learn about what's going on "under the hood." But if that kept me from doing anything other that writing bare ruby I wouldn't use gems. And then I'd be sad. :-(
  • Pikachu
    Pikachu about 12 years
    In order to make it work I had to first install ruby 1.8.7 using rvm. So my recipe would be:
  • Goles
    Goles about 12 years
    This works perfectly well, and I would really recommend using rvm or other equivalent.
  • Geo
    Geo about 11 years
    worked for me on CentOS as well without installing libreadline
  • Luis Ortega Araneda
    Luis Ortega Araneda about 11 years
    It worked fine on Mint. It's a fast solution to this problem. Thanks!
  • Alptigin Jalayr
    Alptigin Jalayr about 11 years
    Worked for me, thanks! Ubuntu 12.10, Ruby 2.0.0 installed via rvm.
  • Mayank Jain
    Mayank Jain about 11 years
  • Houen
    Houen over 10 years
    RVM is outdated and very error-prone. Use rbenv instead: github.com/sstephenson/rbenv
  • Sahil Grover
    Sahil Grover over 10 years
    Thanks for providing this link : rbjl.net/…
  • Evgeniya Manolova
    Evgeniya Manolova over 10 years
    that also worked for me on CentOS5. i've used the solution from this source, though: niwos.com/2011/04/15/fixing-ruby-readline-errors-on-centos