rbenv 无法更改全局 ruby 版本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24736204/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
rbenv can't change global ruby version
提问by qodot
My Mac OS X has a default ruby.
我的 Mac OS X 有一个默认的 ruby。
$ ruby -v
ruby 2.0.0p451 (2014-02-24 revision 45167) [universal.x86_64-darwin13]
I installed rbenv and ruby version 2.1.2.
我安装了 rbenv 和 ruby 版本 2.1.2。
$ rbenv versions
system
* 2.1.2 (set by /Users/sdw/.rbenv/version)
and I tried to set the global ruby version to 2.1.2, but nothing happened.
我尝试将全局 ruby 版本设置为 2.1.2,但没有任何反应。
$ rbenv global 2.1.2
$ ruby -v
ruby 2.0.0p451 (2014-02-24 revision 45167) [universal.x86_64-darwin13]
So I tried to do the same thing with command sudo, but the result is the same.
所以我尝试用 command 做同样的事情sudo,但结果是一样的。
$ sudo rbenv global 2.1.2
$ ruby -v
ruby 2.0.0p451 (2014-02-24 revision 45167) [universal.x86_64-darwin13]
How can I change my global ruby version to 2.1.2? I never installed rvm or other ruby version managing system.
如何将我的全局 ruby 版本更改为 2.1.2?我从未安装过 rvm 或其他 ruby 版本管理系统。
回答by spickermann
Did you add the following lines to your ~/.bash_profile?
您是否将以下几行添加到您的~/.bash_profile?
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
回答by Benj
Type $ rbenv version(without "s")
类型$ rbenv version(不带“s”)
It is possible that output will show a path to the file that is locking the version
输出可能会显示锁定版本的文件的路径
2.0.0p451 (set by /path/to/some/directory/.ruby-version)
It is even possible that the file is a hidden file named .ruby-versionin your current dir. If its the case just remove that .ruby-versionfile
该文件甚至可能是.ruby-version在您当前目录中命名的隐藏文件。如果是这种情况,只需删除该.ruby-version文件
回答by Yoyo Coder
Run the below commands before change ruby version:
在更改 ruby 版本之前运行以下命令:
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
It works for me :)
这个对我有用 :)
回答by Kiryl Plyashkevich
I realize that I occasionally set local ruby version in home folder, from which I use terminal by default :) So that's what worked for me:
我意识到我偶尔会在主文件夹中设置本地 ruby 版本,默认情况下我使用终端 :) 所以这对我有用:
rm /home/MYUSERNAME/.ruby-version
回答by major_finley
I had the same issue ("ruby -v" showing the initial version) but reloading (exit/start) my terminal made the trick.
我有同样的问题(“ruby -v”显示初始版本)但重新加载(退出/启动)我的终端成功了。
Did you try that first?
你先试过吗?
回答by JCLopez
Uninstall ruby and then install agains:
卸载 ruby,然后再次安装:
brew uninstall -f ruby
brew install ruby
Add this two line to you ~/.bash_profile
将这两行添加到您的 ~/.bash_profile
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
Reopen the console and that's it and run
重新打开控制台,然后运行
ruby -v
回答by user461745
instead of:
rbenv global 2.7.1
do:
sudo rbenv global 2.7.1
而不是:
rbenv global 2.7.1
做:
sudo rbenv global 2.7.1

