Is /etc/irbrc installed by OS X? Does irb read it?
Asked Answered
S

1

7

While investigating an issue with irb on my Mac (OS X 10.11.5) I noticed /etc/irbrc. The first few lines follow:

# Some default enhancements/settings for IRB, based on
# http://wiki.rubygarden.org/Ruby/page/show/Irb/TipsAndTricks

unless defined? ETC_IRBRC_LOADED

  # Require RubyGems by default.
  require 'rubygems'

  # Activate auto-completion.
  require 'irb/completion'

# continued ...

It seems to be out of date (rubygarden.org is gone, rubygems is in the standard library these days) and does things that I always thought I had to do in my own ~/.irbrc (set up completion, history, etc.).

It is dated 31 Jan 2016. I might or might not have run an Apple system update or upgraded something else on that date; I don't recall. I've definitely upgraded OS X by a major version or two since then.

I don't think I have any Rubies installed on this computer other than that from OS X and a Ruby 2.3.1 installed with rbenv (in my own account, not as root). That is, I don't think this file could have come from anything other than OS X.

Unix shell convention would lead me to expect that a file named /etc/irbrc would be executed when any user ran irb, before their ~/.irbrc if they had one. However, the irb installed by OS X doesn't appear to read this file: I put puts 1 at the top and don't see the result when I run irb. (I normally use rbenv, but disabled it while investigating this file.) /etc/irbrc doesn't appear to run whether or not I have an ~/.irbrc. Also, I see no mentions of this file in /usr/bin/irb or /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/irb.

My guess is that this file

  • is installed by OS X
  • is not read by irb as is (despite its misleading name and location), but is intended to be copied to ~/.irbrc.

Does anyone know for sure, or know any different?

I don't need or want it; I'm happy to maintain my own ~/.irbrc. I just want to be sure that it isn't affecting irb when I run it (in particular, the irb in the rbenv-installed Ruby that I normally use), and that future OS X upgrades won't change irb behavior.

Send answered 3/6, 2016 at 14:51 Comment(4)
It's on my Yosemite system and I have never done anything with Ruby at all.Coloratura
I think there's an order of priority here in terms of which gets read first. The one in your home directory should supersede it.Lemming
@Lemming no, /etc/irbrc doesn't appear to run for me whether or not I have a ~/.irbrc. I'll note that in my question.Send
It could be the fossilized remnant of earlier times. That is odd, then!Lemming
S
6

Per Mark Setchell's and Jared Beck's comments, /etc/irbrc is installed with current (10.13) OS X and has been for at least a few major releases.

I copied /etc/irbrc to ~/.irbrc, ran irb, exited and got an error: undefined method 'nitems' for ["exit"]:Array (NoMethodError). This method existed in Ruby 1.8 but was removed from Ruby 1.9. I don't normally see this error, so I conclude that /etc/irbrc isn't executed at all.

Overall, I conclude that I can ignore /etc/irbrc when debugging issues with my ~/.irbrc, which was the origin of my question.

Send answered 14/6, 2016 at 19:20 Comment(1)
/etc/irbrc is included in a clean install of OS 10.13Livy

© 2022 - 2024 — McMap. All rights reserved.