rbenv 不改变 ruby​​ 版本 [英] rbenv not changing ruby version

查看:67
本文介绍了rbenv 不改变 ruby​​ 版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照github的说明安装了rbenv.我正在运行 OSX,但我已经在 Ubuntu 12.04 VM 上尝试过,并得到了相同的结果.以下是我尝试更改 ruby​​ 版本时在终端中得到的信息:

rbenv 版本* 1.9.3-p0(由/Users/user/.rbenv/version 设置)1.9.3-p125rbenv 全球1.9.3-p0rbenv 重新哈希红宝石 -vruby 1.8.7 (2011-12-28 patchlevel 357) [universal-darwin11.0]哪个红宝石/usr/bin/ruby

任何人都知道为什么 rbenv 没有像它认为的那样切换 ruby​​ 版本?本地目录中也没有 .rbenv 文件会导致 ruby​​ 版本默认为 1.8.7

rbenv 本地rbenv:没有为此目录配置本地版本

解决方案

检查 PATH 是否包含 $HOME/.rbenv/shims$HOME/.rbenv/bin

$ env |路径

如果使用 bash,还要检查 ~/.bash_profile 中是否包含以下内容,如果使用 zsh,请检查 ~/.zshenv 中是否包含以下内容

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

注意:确保它是您的 ~/.bash_profile 中的最后一个设置.我遇到了一个问题,我安装了一个更新我的 .bash_profile 并重置 PATH 的程序.

最后,确保您的 $HOME 文件夹中没有 .ruby-version 文件,如果您已经做了 $ rbenv local <ruby-version> 在您的 $HOME 文件夹中.做 $rbenv global <ruby-version> 修改了 $HOME/.rbenv/version 文件,并且存在 .ruby-version> $HOME 文件夹中的文件将覆盖由 $HOME/.rbenv/version 设置的版本.

来自文档:

<块引用>

选择 Ruby 版本当您执行 shim 时,rbenv 通过从以下来源读取它来确定要使用的 Ruby 版本,按此顺序:

<块引用>

RBENV_VERSION 环境变量(如果指定).您可以使用 rbenv shell 命令在当前 shell 会话中设置此环境变量.

<块引用>

通过搜索您正在执行的脚本的目录及其每个父目录直到到达文件系统的根目录找到的第一个 .ruby-version 文件.

<块引用>

通过搜索当前工作目录及其每个父目录直到到达文件系统的根目录找到的第一个 .ruby-version 文件.您可以使用 rbenv local 命令修改当前工作目录中的 .ruby-version 文件.

<块引用>

全局 ~/.rbenv/version 文件.您可以使用 rbenv 全局命令修改此文件.如果全局版本文件不存在,rbenv 假定您要使用系统"文件.红宝石——即如果 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

解决方案

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.

这篇关于rbenv 不改变 ruby​​ 版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆