Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby irbrc_history system-wide. How to make it local?

I installed ruby on Ubuntu for system-wide use. The .irbrc_history file is created in a system directory rather than the user's home directory. This causes an access error when the file is owned by someone else. Here's the error besides a bunch more that I think is irrelevant:

irb
/usr/local/rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/irb/ext/save-history.rb:75:in `initialize': Permission denied @ rb_sysopen - /usr/local/rvm/rubies/ruby-2.4.1/.irbrc_history (Errno::EACCES)

Deleting the history file resolves the error.

I tried adding environment variables and history initialization code to what I think is the system .irbrc file, but to no avail.

What is the sequence of initialization files being executed that impact this history file? How can I change the location of the history file?

like image 395
user8742573 Avatar asked Nov 19 '25 07:11

user8742573


2 Answers

Create, or edit your ~/.irbrc file to include:

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

Source: How To Persist Rails or IRB Console Command History After Exit

like image 170
Navin Nair Kottayil Avatar answered Nov 21 '25 07:11

Navin Nair Kottayil


Do you happen to use RVM?

rvm 1.29.3 (current stable) has a bug where IRB history gets saved in the RUBY_HOME instead of HOME.

https://github.com/rvm/rvm/issues/4158

Here's a fix:

rvm get head
rvm reinstall 2.4.1
like image 21
kenn Avatar answered Nov 21 '25 06:11

kenn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!