rbenv not changing ruby version

2019-01-02 19:30发布

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

标签: ruby rbenv
19条回答
十年一品温如言
2楼-- · 2019-01-02 19:52

Make sure the last line of your .bash_profile is:

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
查看更多
流年柔荑漫光年
3楼-- · 2019-01-02 19:53

In my case changing the ~/.zshenv did not work. I had to make the changes inside ~/.zshrc.

I just added:

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

at the top of ~/.zshrc, restarted the shell and logged out.

Check if it worked:

➜  ~ rbenv install 2.4.0
➜  ~ rbenv global 2.4.0
➜  ~ rbenv global
2.4.0
➜  ~ ruby -v
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin16]
查看更多
琉璃瓶的回忆
4楼-- · 2019-01-02 19:57

When I had these symptoms, the problem turned out to be that install had failed halfway through for the new Ruby version I was trying to switch to, without me noticing. The fix was to delete & reinstall it.

(This meant that even though ruby 1.9.3 showed up in the rbenv list of available versions, it didn't have an executable on the path where rbenv assumed it would. Since rbenv tries to change your ruby version just by prepending a location to your path, if there's nothing actually in the location it prepends, your OS will happily continue searching your default path and find your system version, in my case like the question's 1.8.7.)

查看更多
梦寄多情
5楼-- · 2019-01-02 19:57

As for me the easiest way to use rbenv along with zsh is adding rbenv to plugins section in .zshrc config. In my case it looks similar to:

# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git bower rails ruby rbenv gulp npm node nvm sublime)

After that there're no problems when installing, switching, using ruby versions with help of rbenv.

Mind to restart your terminal session after made changes.

查看更多
骚的不知所云
6楼-- · 2019-01-02 19:58

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 is no ~/.rbenv/bin directory, which was mentioned in the post by @rodowi.

查看更多
何处买醉
7楼-- · 2019-01-02 19:59

I forgot to delete rvm before installing rbenv. I deleted rvm and re-installed rbenv, but system still wasn't using the version of Ruby being designated as global by rbenv. I tried shutting Terminal, but it only worked once I restarted the whole machine.

查看更多
登录 后发表回答