rbenv not changing ruby version

Check that PATH contains $HOME/.rbenv/shims and $HOME/.rbenv/bin

$ env | grep PATH

Also check that you have the following in your ~/.bash_profile if using bash or ~/.zshenv if using zsh

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

NOTE: Make sure it's the last setting in your ~/.bash_profile . I ran into an issue where I installed a program that updated my .bash_profile and reset PATH.

Finally, make sure your $HOME folder doesn't have a .ruby-version file that you may have created by accident if you were to have done $ rbenv local <ruby-version> in your $HOME folder. Doing $ rbenv global <ruby-version> modifies the $HOME/.rbenv/version file, and the existence of a .ruby-version file in the $HOME folder would override the version set by $HOME/.rbenv/version.

From the docs:

Choosing the Ruby Version When you execute a shim, rbenv determines which Ruby version to use by reading it from the following sources, in this order:

The RBENV_VERSION environment variable, if specified. You can use the rbenv shell command to set this environment variable in your current shell session.

The first .ruby-version file found by searching the directory of the script you are executing and each of its parent directories until reaching the root of your filesystem.

The first .ruby-version file found by searching the current working directory and each of its parent directories until reaching the root of your filesystem. You can modify the .ruby-version file in the current working directory with the rbenv local command.

The global ~/.rbenv/version file. You can modify this file using the rbenv global command. If the global version file is not present, rbenv assumes you want to use the "system" Ruby—i.e. whatever version would be run if rbenv weren't in your path.


I fixed this by adding the following to my ~/.bash_profile:

#PATH for rbenv
export PATH="$HOME/.rbenv/shims:$PATH"

This is what is documented at https://github.com/sstephenson/rbenv.

From what I can tell there isn't ~/.rbenv/bin directory, which was mentioned in the post by @rodowi.


This may be an old question, but Google led me here and, for posterity sake, thought I'd share.

My problem persisted after many of the recommended solutions above. Like the OP, I installed rbenv and then a ruby version, but my laptop defaulted to system. What I had overlooked was that when I ran:

[~/.rbenv] $ rbenv versions
* system (set by /Users/alphadogg/.rbenv/version)
  2.0.0-p247

IOW, it was still defaulting to system. A quick

[~/.rbenv] $ rbenv local 2.0.0-p247

switched it to the new version.


First step is to find out which ruby is being called:

$ which ruby

Your system says:

/usr/bin/ruby

This is NOT the shim used by rbenv, which (on MacOS) should look like:

/Users/<username>/.rbenv/shims/ruby

The shim is actually a script that acts like a redirect to the version of ruby you set.

I recommend that for trouble shooting you unset the project specific "local" version, and the shell specific "shell" version and just test using the "global" version setting which is determined in a plain text file in ~/.rbenv/version which will just be the version number "1.9.3" in your case.

$ rbenv global 1.9.3
$ rbenv local --unset
$ rbenv shell --unset

You can do ls -laG in the root of your project folder (not the home folder) to make sure there is no longer a ".ruby-version" file there.

You can use rbenv versions to identify which version rbenv is set to use (and the location and name of the file that is setting that):

$ rbenv versions

NONE OF THAT MATTERS until you set the path correctly.

Use this to make sure your *MacOS will obey you:

$ rbenv init -

Followed by:

$ which ruby

To make sure it looks like:

/Users/<username>/.rbenv/shims/ruby

Then run this to add the line to your profile so it runs each time you open a new terminal window:

$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile

There are other ways to modify the path, feel free to substitute any of them instead of running the rbenv init.

NOTE: reinstall Rails with:

$ gem install rails

If you were trying to run Ruby on Rails, then you need to have this all working first, then install the rails gem again. A previous install of Rails will use a hard coded path to the wrong ruby and several other things will be in the wrong place, so just install the gem again.

P. S. If your MacOS won't obey you (*mentioned above) then you may have to find another way to modify your path, but that's unlikely to be a problem because "Macs just work" ;)


I just found this same problem. What I did was uninstall rbenv (via homebrew) and reinstall it. I also added

if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi

into ~/.bash_profile when I reinstalled rbenv. Works perfectly now.