18

I install ruby via rbenv-installer.

When I use irb console, I can use history by pressing up and down on keyboard. And when I exited from console and start it again, I can't use prewious history. When I press up-arrow-button, nothing was happened.

When I used rvm this option was working. How can I switch on it in rbenv?

arturtr
  • 1,115
  • 9
  • 18
  • See also https://stackoverflow.com/questions/37847822/irb-history-not-working-with-ruby-2-3-0?noredirect=1&lq=1 which discusses how ruby must be complied with `readline` – Jared Beck Jan 31 '18 at 17:04

2 Answers2

45

I found this way for solving my problem. In file ~/.irbrc write:

require 'irb/ext/save-history'
#History configuration
IRB.conf[:SAVE_HISTORY] = 100
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history"

Found in this question: irb history not working

Community
  • 1
  • 1
arturtr
  • 1,115
  • 9
  • 18
  • 9
    Adding just the `IRB.conf[:SAVE_HISTORY] = 10000` line was sufficient to fix things for me. – Jordan Brough Feb 14 '14 at 15:59
  • 2
    If this doesn't work, and you are on OS X, you may need to update your Readline library. See http://stackoverflow.com/questions/37847822/irb-history-not-working-with-ruby-2-3-0 – Evan Pon Jun 16 '16 at 00:49
  • I had the same issue on OS X that @EvanPon described. I had to update my Readline library and reinstall Ruby via rbenv. See the post he linked for details. – Nick Fishman Sep 03 '16 at 02:48
  • This doesn't work for me, in Ubuntu 14.04. I know that `~/.rbrc` is being processed because I put a `puts` at the top. But it just doesn't make any difference. I have Readline installed - at least, I can do `Readline` in the console. – Max Williams May 04 '18 at 14:58
12

Create ~/.irbrc if it does not exist, and add the following line to it:

IRB.conf[:SAVE_HISTORY] = 1000
Weston Ganger
  • 6,324
  • 4
  • 41
  • 39