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:36

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.

查看更多
临风纵饮
3楼-- · 2019-01-02 19:38

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.

查看更多
柔情千种
4楼-- · 2019-01-02 19:38

You could try using chruby? chruby does not rely on shims, instead it only modifies PATH, GEM_HOME, GEM_PATH.

查看更多
皆成旧梦
5楼-- · 2019-01-02 19:39

This happened to me right after I reinstalled rbenv. Apparently I had a .ruby-version file in my home directory, specifying a version that no longer existed. Once I deleted the file, everything worked.

查看更多
几人难应
6楼-- · 2019-01-02 19:40

for fish shell user

set --universal fish_user_paths $fish_user_paths ~/.rbenv/shims/
查看更多
还给你的自由
7楼-- · 2019-01-02 19:40

Strangely, rbenv version did not set the .rbenv file Check with: ls -ltra --> to see that a rbenv was written

查看更多
登录 后发表回答