2

I switched from RVM to rbenv recently and I can't seem to switch between ruby versions even though 'rbenv versions' tells me I have the version I want to switch to.

Here is what Im doing:

ruby -v
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]

I would like to switch to 1.9.2-p290 so lets make sure I have it in my versions:

ruby versions
1.8.7-p370
1.9.2-p290
1.9.3-p125
1.9.3-rc1

Ok great now that I see I have it lets try and change the global rbenv:

rbenv global 1.9.2-p290
ruby -v
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]

Seems 1.8.7 is still the active global ruby.

So, lets try and make it local in my project. rbenv local 1.9.2-p290

This creates a .rbenv-versions file in my rails project. Great lets try and run bundle:

Gem::InstallError: factory_girl requires Ruby version >= 1.9.2.
An error occurred while installing factory_girl (4.1.0), and Bundler cannot continue.
Make sure that `gem install factory_girl -v '4.1.0'` succeeds before bundling. 

I'm not sure what to do next...

Darion Miller
  • 31
  • 1
  • 4
  • Ok so I *Think* I figured out the issue. I found this: http://stackoverflow.com/questions/10940736/rbenv-not-changing-ruby-version/11708787#11708787 But that wasn't quite the issue cause I only have one 0.3.0 version. So i removed it anyways and put a local copy on my desktop. Ran rbevn global [change] and obviously it didn't work. I put the same file back in and then ran the change global ruby command back and it fixed whatever issue I was having. – Darion Miller Dec 14 '12 at 18:50
  • 1
    It is so curious that questions like this stay unanswered. Me and most people I know really struggle just getting a different Ruby version to work on OSX. And somehow, it seems impossible to find the right answers, even on Github. – Micros Sep 12 '13 at 20:04
  • Since this still shows up in 2021, what worked for me was to add these commands in the terminal: export PATH="$HOME/.rbenv/bin:$PATH" eval "$(rbenv init -)" – Matt West Mar 26 '21 at 20:59

2 Answers2

5

I solved this today on a (OSX) computer of a friend, the problem probably is that you have RVM and Rbenv installed at the same time, first you have to make sure RVM is removed;

In the terminal execute:

sudo rm -rf ~/.rvm

When this is done, reopen the terminal. Then try ruby -v, the version you see is probably the system version ruby 1.8.7. Then try again to select the right Ruby version with Rbenv:

rbenv global 2.0.0-p247

Also, be sure Rbenv is in your path:

echo $PATH
=> /Users/jankeesvw/.rbenv/bin:/Users/jankeesvw/.rbenv/shims:/Users/jankeesvw/.rbenv/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/mysql/bin

If this Rbenv is not in your path, follow the instructions on the Rbenv github page

Jankeesvw
  • 711
  • 8
  • 18
  • 1
    You are, as promised when I tweeted you this question, my hero. Finally my Ruby is not 1.8.7 anymore. One of the many, many gotchas was modifying .zshrc instead of .bash_profile. (Next challenge is rake jasmine, but that's not part of this question.) – Micros Sep 13 '13 at 14:16
  • If the PATH has no .rbenv then execute: – juan Isaza Dec 24 '15 at 18:35
3

If $ echo $PATH

has no .rbenv then execute:

$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile

and restart shell.

juan Isaza
  • 3,646
  • 3
  • 31
  • 37
  • And for ~/.zshr substitute for~/.bash_profile like thisc$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zschr $ echo 'eval "$(rbenv init -)"' >> ~/.zschr worked for me. – uberdave Apr 12 '21 at 01:28