33

I just installed ruby 1.9.2 on windows machine and Backspace or any other arrow keys don't work. This happens only when I open IRB on Git Bash console. But it works fine on Windows console. Any help on that?

Note: IRB was working fine on both consoles with the earlier versions of ruby.

Vineeth Pradhan
  • 8,201
  • 7
  • 33
  • 34

6 Answers6

47

Same thing happened to me. Running irb with --noreadline solved my problem:

irb --noreadline
Neno Ganchev
  • 746
  • 8
  • 14
  • 2
    This solution worked like a charm. I changed my `irb` script to add it automatically to command line arguments. For others, my script was in `C:\Ruby\1.9.3\bin\irb` and I added `ARGV << "--noreadline"` just after the `require 'irb'` statement. – Matt May 02 '13 at 13:28
  • 7
    You can make it default behavior with bash alias: `alias irb='irb --noreadline'` – Dmitriy Budnik May 29 '13 at 06:39
  • It is helpful but does not really solve the issue, at least in my case. Whenever I want to do a simple operation this is not the way to go. – João Gouveia Jul 25 '19 at 07:43
9

You can also disable readline in ~/.irbrc

IRB.conf[:USE_READLINE] = false
Bo Frederiksen
  • 2,087
  • 1
  • 14
  • 21
9

Seems you didn't have readline installed while compile ruby. So install readline, maybe also readline-devel, then recompile ruby.

Cheng
  • 4,816
  • 4
  • 41
  • 44
7

As documented here https://groups.google.com/forum/#!topic/rubyinstaller/HgswOz1T-eE, use the below command/alias:

alias irb="ruby -S irb"

If that doesn't work, use pry instead:

gem install pry
konyak
  • 10,818
  • 4
  • 59
  • 65
5

Install the rb-readline gem.

gem install rb-readline
DoctorRu
  • 1,063
  • 1
  • 13
  • 15
0

Brief answer I had to do brew upgrade,(Apparently the situation, according to a ruby expert I spoke to, is that "There's a new default gem in trunk, Reline, that's a readline fallback.") . Then a new window and arrow keys in irb worked. Then sudo gem install pry, new window, and pry worked. ruby --version fell to 2.3 and I had to do brew install ruby, it said ruby 2.6 already installed and to do brew reinstall ruby, and it said to update the path, I did that and then fine. ruby 2.6 installed. edit- now rails is broken.. i'll update further.

More elaborate answer.

I had this issue of ruby irb arrow keys not working,

~/blah$ irb
irb(main):001:0> ^[[A^[[D^[[B^[[C

I am on osx, and don't think I had this issue some months ago

and also had an error when starting pry, pry<ENTER> it says "Reason: image not found - /usr/local/Cellar/ruby/2.5.0/lib/ruby/2.5.0/x86_64-darwin16/readline.bundle"

I tried brew link readline --force it didn't help, I tried irb --noreadline it didn't help

But what worked for me was this from a ruby expert- brew upgrade

Apparently the situation, according to a ruby expert I spoke to, is that "There's a new default gem in trunk, Reline, that's a readline fallback."

Then I started a new terminal window and $irb worked with arrow keys.

I then did sudo gem install pry , opened a new terminal window, and pry worked.

Ruby fell back to 2.3 when it should really be 2.6 and I thought it was 2.6

So I did brew install ruby, it said ruby 2.6 was already installed, and suggested brew reinstall ruby. so I did brew reinstall ruby . Opened a new terminal window. It was still on 2.3. But it suggested adding export PATH="/usr/local/opt/ruby/bin:$PATH" to .bash_profile (a file on osx that runs automatically). I did that it didn't work, but doing PATH="/usr/local/opt/ruby/bin:$PATH" manually at the start of each terminal session works.

edit- now rails is broken , i'll update further.

I got gem to work when I ran the one after updating the path..

This solution is not ideal as it gives two versions of ruby, and thus of course two versions of gem

Last login: Fri Aug  9 16:02:48 on ttys001
have run /Users/apple/.bash_profile
~$ cd /usr/local/opt/ruby/bin
/usr/local/opt/ruby/bin$ ls
bundle  bundler erb gem irb rake    rdoc    ri  ruby
/usr/local/opt/ruby/bin$ echo $PATH
/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:~/rubymac/rubyrailshelperscripts:/opt/X11/bin:/Users/apple/.vimpkg/bin:/usr/local/opt/fzf/bin
/usr/local/opt/ruby/bin$ which gem
/usr/bin/gem
/usr/local/opt/ruby/bin$ cd ~/
~$ /usr/local/opt/ruby/bin/ruby --version
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin16]
~$ /usr/bin/ru
ruby      runocc.d  
~$ /usr/bin/ruby --version
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin16]
~$ 
barlop
  • 12,887
  • 8
  • 80
  • 109
  • briefer answer- I had to do brew upgrade,(Apparently the situation, according to a ruby expert I spoke to, is that "There's a new default gem in trunk, Reline, that's a readline fallback.") then a new window and arrow keys in irb worked. Then sudo gem install pry, new window, and pry worked. ruby --version fell to 2.3 and I had to do brew install ruby, it said ruby 2.6 already installed and to do brew reinstall ruby, and it said to update the path, I did that and then fine. ruby 2.6 installed. – barlop Aug 03 '19 at 15:43