Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rbenv not changing ruby version

Tags:

ruby

rbenv

I installed rbenv according to the github directions. I am running OSX but I have tried this on a Ubuntu 12.04 VM and got the same results. The following is what i get in my terminal when I try to change ruby versions:

rbenv versions * 1.9.3-p0 (set by /Users/user/.rbenv/version) 1.9.3-p125  rbenv global 1.9.3-p0  rbenv rehash  ruby -v ruby 1.8.7 (2011-12-28 patchlevel 357) [universal-darwin11.0]  which ruby /usr/bin/ruby 

Anyone have any ideas as to why rbenv isn't switching the ruby version like it thinks it is? Also there is no .rbenv file in the local directory that would be causing the ruby version to default to 1.8.7

rbenv local rbenv: no local version configured for this directory 
like image 679
ajorgensen Avatar asked Jun 07 '12 22:06

ajorgensen


People also ask

How do I choose Ruby for Rbenv?

rbenv/shims and detect which Ruby version you want to use. They insert the directory for the selected version at the beginning of your $PATH and then execute the corresponding binary. Because of the simplicity of the shim approach, all you need to use rbenv is ~/. rbenv/shims in your $PATH .

How do I change Ruby version on Mac?

Set Ruby version with rvm on Mac 0 on the command line. To switch to the system ruby, enter rvm use system . To switch back to the default, rvm default . The command rvm list will show all installed Rubies, including the current and default versions.

Does Rbenv install Ruby?

Rbenv by itself does not install Ruby implementations at all. You simply give it the path to an already installed Ruby implementation. There are several projects that make installing Ruby implementations easier.

Is Rbenv better than RVM?

Rbenv pros over RVM: Rbenv is lightweight, RVM is heavier, Rbenv is more developer-friendly than RVM, Rbenv has a dedicated plugin for Ruby installation mechanism, RVM has it built-in.


2 Answers

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.

like image 74
defvol Avatar answered Sep 21 '22 03:09

defvol


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.

like image 35
mjmdavis Avatar answered Sep 24 '22 03:09

mjmdavis