我根据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
这里的所有其他答案都为各种情况提供了很好的建议,但还有一种更简单的方法。
rbenv文档向我们指出了rbenv-doctor诊断工具,该工具将快速验证系统上的所有这些潜在缺陷:
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash
当一切顺利时,你会看到:
$ curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash <aws:hd-pmp-developer>
Checking for `rbenv' in PATH: /usr/local/bin/rbenv
Checking for rbenv shims in PATH: OK
Checking `rbenv install' support: /usr/local/bin/rbenv-install (ruby-build 20201005)
Counting installed Ruby versions: 1 versions
Checking RubyGems settings: OK
Auditing installed plugins: OK
现在,如果我们打破了这些期望之一(例如删除rbenv-install),该工具将直接指向我们的问题,并提供了如何修复它的链接:
$ mv /usr/local/bin/rbenv-install rbenv-install-GONE
$ curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash
Checking for `rbenv' in PATH: /usr/local/bin/rbenv
Checking for rbenv shims in PATH: OK
===> Checking `rbenv install' support: not found <===
Unless you plan to add Ruby versions manually, you should install ruby-build.
Please refer to https://github.com/rbenv/ruby-build#installation
Counting installed Ruby versions: 1 versions
Checking RubyGems settings: OK
Auditing installed plugins: OK
有很多误导性的答案是有效的。我认为值得一提的是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>