rbenv can't change global ruby version

淺唱寂寞╮ 提交于 2019-12-03 09:08:39

问题


My Mac OS X has a default 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 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.

$ 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.

$ 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.


回答1:


Did you add the following lines to your ~/.bash_profile?

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

See: https://github.com/sstephenson/rbenv#installation




回答2:


Type $ rbenv version (without "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-version in your current dir. If its the case just remove that .ruby-version file




回答3:


Run the below commands before change ruby version:

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

It works for me :)




回答4:


I had the same issue ("ruby -v" showing the initial version) but reloading (exit/start) my terminal made the trick.

Did you try that first?




回答5:


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:

rm /home/MYUSERNAME/.ruby-version



回答6:


Uninstall ruby and then install agains:

brew uninstall -f ruby
brew install ruby

Add this two line to you ~/.bash_profile

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

Reopen the console and that's it and run

ruby -v 


来源:https://stackoverflow.com/questions/24736204/rbenv-cant-change-global-ruby-version

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!