All commands in irb giving "NoMethodError: undefined method `write' for nil:NilClass"
Asked Answered
B

1

8

I am trying to get the current ruby version from IRB but its giving me this error:

>> RUBY_VERSION
NoMethodError: undefined method `write' for nil:NilClass
    from /usr/local/lib/ruby/1.9.1/irb.rb:311:in `printf'
    from /usr/local/lib/ruby/1.9.1/irb.rb:311:in `output_value'
    from /usr/local/lib/ruby/1.9.1/irb.rb:160:in `block (2 levels) in eval_input'
    from /usr/local/lib/ruby/1.9.1/irb.rb:273:in `signal_status'
    from /usr/local/lib/ruby/1.9.1/irb.rb:156:in `block in eval_input'
    from /usr/local/lib/ruby/1.9.1/irb/ruby-lex.rb:243:in `block (2 levels) in each_top_level_statement'
    from /usr/local/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `loop'
    from /usr/local/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `block in each_top_level_statement'
    from /usr/local/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in `catch'
    from /usr/local/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in `each_top_level_statement'
    from /usr/local/lib/ruby/1.9.1/irb.rb:155:in `eval_input'
    from /usr/local/lib/ruby/1.9.1/irb/ext/multi-irb.rb:166:in `block (2 levels) in irb'
    from /usr/local/lib/ruby/1.9.1/irb/ext/multi-irb.rb:165:in `catch'
    from /usr/local/lib/ruby/1.9.1/irb/ext/multi-irb.rb:165:in `block in irb'
Maybe IRB bug!

ruby -v shows ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.2.0]

I am using Mac OS X Lion

UPDATE: Actually, it doesn't run anything at all.

>> a = 'Hello, World!'
NoMethodError: undefined method `write' for nil:NilClass
    from /usr/local/lib/ruby/1.9.1/irb.rb:311:in `printf'
    from /usr/local/lib/ruby/1.9.1/irb.rb:311:in `output_value'
    from /usr/local/lib/ruby/1.9.1/irb.rb:160:in `block (2 levels) in eval_input'
    from /usr/local/lib/ruby/1.9.1/irb.rb:273:in `signal_status'
    from /usr/local/lib/ruby/1.9.1/irb.rb:156:in `block in eval_input'
    from /usr/local/lib/ruby/1.9.1/irb/ruby-lex.rb:243:in `block (2 levels) in each_top_level_statement'
    from /usr/local/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `loop'
    from /usr/local/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `block in each_top_level_statement'
    from /usr/local/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in `catch'
    from /usr/local/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in `each_top_level_statement'
    from /usr/local/lib/ruby/1.9.1/irb.rb:155:in `eval_input'
    from /usr/local/lib/ruby/1.9.1/irb/ext/multi-irb.rb:166:in `block (2 levels) in irb'
    from /usr/local/lib/ruby/1.9.1/irb/ext/multi-irb.rb:165:in `catch'
    from /usr/local/lib/ruby/1.9.1/irb/ext/multi-irb.rb:165:in `block in irb'
Maybe IRB bug!

UPDATE # 2: (For the Tin Man) Using /usr/bin/irb, I get

>> 5+5
NoMethodError: undefined method `write' for nil:NilClass
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:310:in `printf'
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:310:in `output_value'
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:159:in `eval_input'
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:271:in `signal_status'
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:155:in `eval_input'
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb/ruby-lex.rb:244:in `each_top_level_statement'
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb/ruby-lex.rb:230:in `loop'
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb/ruby-lex.rb:230:in `each_top_level_statement'
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb/ruby-lex.rb:229:in `catch'
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb/ruby-lex.rb:229:in `each_top_level_statement'
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:154:in `eval_input'
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:71:in `start'
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:70:in `catch'
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:70:in `start'
    from /usr/bin/irb:13
Maybe IRB bug!!
Bohannan answered 6/2, 2012 at 20:16 Comment(7)
What does ruby -v show when you run it at a command line? What OS are you using? Does your irb work at all? Do you have a .irbrc file?Experienced
updated my question with more info.Bohannan
You are right, it doesn't work at all.Bohannan
IRB on Lion should be in /usr/bin/irb, not based in /usr/local/... so you are running on a modified Mac OS. How did you install 1.9.3?Faretheewell
Mac OS X came with 1.8.7. I installed 1.9.3 by following this guide: hivelogic.com/articles/ruby-rails-leopardBohannan
So you installed Ruby on Lion using the instructions for Leopard.Faretheewell
I thought it would be the same thing, guess it wasn'tBohannan
F
1

Try /usr/bin/irb to get to Apple's installation of Ruby.

Installing Ruby on Lion using instructions for Leopard isn't a good idea. You have to remember that languages and OS details change.

The information at "Building Ruby 1.9.3 on Lion with Xcode 4.2 using ./configure --with-gcc=clang" should help. Also "Error installing 1.9.3 with RVM on Lion" has useful information about XCode.

Faretheewell answered 6/2, 2012 at 21:25 Comment(3)
I mean, try typing that in at the command-line and see what it does. Apple pre-installs Ruby for their own use and /usr/bin/irb is their instance of IRB. If it works you know your installation of 1.9.3 is hosed and you need to follow different directions.Faretheewell
Ah. just did. I get long error. I'll update my question with the new log.Bohannan
Because two different versions of Ruby, one of which is Apple's build, are showing identical problems, I suspect the problem isn't Ruby but something else in your system. Have there been any other changes to your OS, such as installing other command-line applications or replacing any libraries?Faretheewell

© 2022 - 2024 — McMap. All rights reserved.