我根据github的说明安装了rbenv。我正在运行OSX,但我已经在Ubuntu 12.04虚拟机上尝试了这一点,并得到了相同的结果。下面是当我尝试更改ruby版本时,在我的终端中得到的结果:

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

有人知道为什么rbenv没有像它认为的那样切换ruby版本吗?此外,本地目录中没有.rbenv文件,这将导致ruby版本默认为1.8.7

rbenv local
rbenv: no local version configured for this directory

当前回答

确保.bash_profile的最后一行是:

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

其他回答

奇怪的是,rbenv版本没有设置.rbenv文件。

使用:ls -ltra——>检查rbenv是否被写入。

执行此命令

将rbenv添加到bash中,以便在每次打开终端时加载它

echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
source ~/.bash_profile

这将解决你的问题

有很多误导性的答案是有效的。我认为值得一提的是rbenv README的步骤。

$ brew安装rbenv $ rbenv init并按照它给出的指示执行。这是我得到的:

~ $ rbenv init
# Load rbenv automatically by appending
# the following to ~/.bash_profile:

eval "$(rbenv init -)"

我更新了~/.bash_profile…

关闭终端,重新打开 通过运行以下命令来验证它是否正常工作:

$ curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash

现在只需安装你想要的版本:rbenv install <version>

我通过在我的~/.bash_profile中添加以下内容来修复这个问题:

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

这是https://github.com/sstephenson/rbenv上的文档。

据我所知,没有~/。Rbenv /bin目录,@rodowi在帖子中提到过。

对我来说,使用rbenv和zsh最简单的方法是将rbenv添加到.zshrc配置中的插件部分。在我的例子中,它看起来类似于:

# 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)

在rbenv的帮助下,安装、切换和使用ruby版本都没有问题。

注意在做出更改后重新启动终端会话。