Backspace and arrow keys aren't working in IRB(Git Bash console) on windows machine
Asked Answered
E

6

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.

Emend answered 14/4, 2011 at 7:59 Comment(0)
P
47

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

irb --noreadline
Potshot answered 8/11, 2011 at 22:2 Comment(3)
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.Uncloak
You can make it default behavior with bash alias: alias irb='irb --noreadline'Lotti
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.Caste
D
9

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

Dimitrovo answered 24/6, 2011 at 5:44 Comment(2)
Usually, it comes pre-compiled on Windows version. It's not an easy task to recompile correctly under Windows platform.Uncloak
I had the same issue on Fedora 30. After recompiling it's working for me.Ingra
S
9

You can also disable readline in ~/.irbrc

IRB.conf[:USE_READLINE] = false
Sylphid answered 18/9, 2013 at 9:49 Comment(1)
Neno's answer above did not work, not sure why. But adding this into .irbrc worked for me. Thanks!Ovarian
H
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
Hildie answered 29/1, 2014 at 19:7 Comment(0)
M
5

Install the rb-readline gem.

gem install rb-readline
Mazonson answered 31/12, 2013 at 2:35 Comment(2)
Didnt help me either.Chrystal
After installing the gem, it needs to be required by either adding it to Gemfile or require 'rb-readline'Ingra
M
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]
~$ 
Mclaren answered 3/8, 2019 at 15:37 Comment(1)
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.Mclaren

© 2022 - 2024 — McMap. All rights reserved.