It was ruining all my mood and concentration when i was trying some sample ruby code in irb and again and again i had to retype the things because the arrow keys were not working there. I searched the problem on net and found that i need to have readline library on my linux and in ruby as well. Now the point is readline should be available on the linux before you compile ruby so as you can give the readline option while compiling ruby. BUT we have ruby already installed !! Now What ?

Now, first you will need to install system based readline libraries as

  sudo apt-get install libreadline5 libreadline5-dev

If you are not able to install linux based readline with the above method the refer this for more details.

Now you will need to compile the ruby based readline interface to let you readline library available in irb.
Do it by this…

  cd /usr/local/src/ruby-1.8.6/ext/readline
  sudo ruby extconf.rb
  sudo make
  sudo make install

thats it, all done!!
Try your tips on arrow keys in irb, it should work now.
enjoy!!

8 Comments to "How to make arrow keys working in irb in Linux/Ubuntu"

  • Jeet said:

    Hi

    Hey You are a ruby people and you are using php for your ruby site if we ruby people will not promote Ruby How will ruby SPREAD ?

  • sur said:

    Hey Jeet,

    I hope i will get time to switch on to Mephisto or else soon !

  • Makuchaku said:

    Hi,

    Nice blog!

    Try http://www.rubyinside.com/wirble-tab-completion-and-syntax-coloring-for-irb-336.html for more cool stuff on IRB - output coloring and tab completion

    PS: I read that you are a .NET convert - dude, you’ve converted pretty well :) :) Maku

  • sur said:

    Thanks Maku!!

    thats really useful gem for irb.

  • KevinC said:

    Thanks for this post ! It saved me.

    Especially this line:
    sudo apt-get install libreadline5 libreadline5-dev

  • Instalar Ruby 1.9 junto a Ruby 1.8 en Ubuntu 9.04 Jaunty Jackalope | lobo_tuerto said:

    [...] Installing Ruby 1.8 and 1.9 Side by Side Multiple Versions of Ruby on Ubuntu #3 How to make arrow keys working in irb in Linux/Ubuntu [...]

  • zipizap123 said:

    I use RubyVersionManager (rvm) to download/update severall ruby versions in paralell, and I had the same problem with irb keys in all the ruby versions installed with rvm.

    To fix the irb of one of the ruby versions installed - in this case the ruby-1.9.1-p378 - I’ve done a slightly changed version of the commands posted above:

    sudo apt-get install libreadline5 libreadline5-dev
    cd ~/.rvm/src/ruby-1.9.1-p378/ext/readline/
    ruby extconf.rb
    make install

    I believe that if you want to fix the irb of another of the ruby versions installed, you will have to do the same cd + ruby extconf.rb + make install in the corresponding directory of that specific ruby version.

    PS: The rvm is the best way I found to download the latest ruby version available and still keep an older ruby version side-by-side without conflicts (it even keeps seperate gems versions apart, so they don’t conflict with each other - in short, you can have several rubys/gems versions installed and select which of them to use when you want, very easy to use)

  • Fix for irb. backspace and arrow keys doesn’t work « Flashes of Insight said:

    [...] As usual, I had to go in search for the cause and solution. After bit of googling I fell on a right blogpost. The problem/fix explained was exactly same and that fix worked for [...]

Please share your thoughts