gpt4 book ai didi

ruby - rbenv 不改变 ruby​​ 版本

转载 作者:数据小太阳 更新时间:2023-10-29 06:16:29 26 4
gpt4 key购买 nike

我根据 github 说明安装了 rbenv。我正在运行 OSX,但我已经在 Ubuntu 12.04 VM 上尝试过并得到相同的结果。以下是我尝试更改 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

最佳答案

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

$ env | grep PATH

如果使用 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 设置的版本.

来自文档:

Choosing the Ruby VersionWhen 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.

关于ruby - rbenv 不改变 ruby​​ 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10940736/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com