3

I started using rbenv for ruby version management and I'm finding that irb not loading the correct ruby version and gem version. Here are the details.

irb Gem.path says:

`>> Gem.path  
 => ["/Users/Air/.gem/ruby/1.8", "/Library/Ruby/Gems/1.8", "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8"]`

Now in irb if I type: puts $:

`>> puts $:  
/Library/Ruby/Site/1.8  
/Library/Ruby/Site/1.8/powerpc-darwin11.0  
/Library/Ruby/Site/1.8/universal-darwin11.0  
/Library/Ruby/Site  
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/vendor_ruby/1.8 /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/vendor_ruby/1.8/universal-darwin11.0  
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/vendor_ruby  
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8  
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/powerpc-darwin11.0  
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin11.0`

In the shell I type: gem env

`RubyGems Environment:  
  - RUBYGEMS VERSION: 1.8.10  
  - RUBY VERSION: 1.9.2 (2011-07-09 patchlevel 290) [x86_64-darwin11.0.1]  
  - INSTALLATION DIRECTORY: /Users/Air/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1  
  - RUBY EXECUTABLE: /Users/Air/.rbenv/versions/1.9.2-p290/bin/ruby  
  - EXECUTABLE DIRECTORY: /Users/Air/.rbenv/versions/1.9.2-p290/bin  
  - RUBYGEMS PLATFORMS:  
    - ruby  
    - x86_64-darwin-11  
  - GEM PATHS:  
     - /Users/Air/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1  
     - /Users/Air/.gem/ruby/1.9.1  
  - GEM CONFIGURATION:  
     - :update_sources => true  
     - :verbose => true  
     - :benchmark => false   
     - :backtrace => false  
     - :bulk_threshold => 1000  
  - REMOTE SOURCES:  
     - http://rubygems.org/`  

I can see that irb is loading the wrong Ruby version and loading the wrong Gem path. Can someone help understand how do I fix this. I am using rbenv for ruby version management not sure how that plays into things. Advice?

alenm
  • 1,013
  • 3
  • 15
  • 34
  • Where/how did you set the current Ruby version using rbenv? – Andrew Marshall Dec 03 '11 at 01:45
  • The instructions on the rbenv site said to use `rbenv global`. The exact instructions say `global Set or show the global Ruby version`. If I run `rbenv global` in my shell it says **1.9.2-p290** – alenm Dec 03 '11 at 02:07
  • 1
    You probably have the system-wide irb in your path (run `which irb` to confirm). This irb will load something like `/usr/bin/ruby`, which will bypass rbenv. I'm not familiar with rbenv, but I see this same type of problem here on SO all the time. Rename your system-wide irb to something like `irb_old` and make sure your rbenv directory is in your path `echo $PATH` and you should get it working. – Casper Dec 03 '11 at 02:14
  • OK I renamed the rib to (irb_old). When I type `echo $PATH` I get `/Users/Air/.rbenv/shims:/Users/Air/.rbenv/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin` ...and now when I type `irb` I get `command not found` I don't think that's the solution, but thanks for the suggestion. And I did restart my shell. – alenm Dec 03 '11 at 02:24
  • Is it possible that maybe Ruby 1.9.2 did not install **irb** and that's why it's not working. How can I install irb – alenm Dec 03 '11 at 02:32
  • 1
    You might want to try `irb1.9.1`. When there is an existing Ruby 1.8 install, 1.9 wont override the symbolic links `irb`, `gem`, `ruby`, etc. – Linuxios Dec 03 '11 at 02:39
  • 1
    What does `which ruby` say? If it loads the ruby in your rbenv directory, then edit the first line in your `irb_old` to `#!/usr/bin/env ruby`, and rename back to `irb`. Now try again. I don't know why irb was not installed properly..but the above workaround should fix that. – Casper Dec 03 '11 at 02:43
  • PERFECT! I changed it to `#!/usr/bin/env ruby` now irb is looking at the right Ruby version and Gem path. Thanks so much. – alenm Dec 03 '11 at 03:07

2 Answers2

10

Make sure you are setting your path correctly and initializing rbenv in the shell you are using.

I've added the following lines to my .bash_profile:

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

I had the problems you are exhibiting until I remembered to do this.

Also remember to set your global rbenv version of ruby

adisney
  • 101
  • 2
6

Once installed ruby using rbenv.

Have you rebuilded the shim binaries using the command

$ rbenv rehash

Thillai Narayanan
  • 4,766
  • 5
  • 32
  • 39