简体   繁体   English

rbenv 无法更改全局 ruby​​ 版本

[英]rbenv can't change global ruby version

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.所以我尝试用命令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?如何将我的全局 ruby​​ 版本更改为 2.1.2? I never installed rvm or other ruby version managing system.我从未安装 rvm 或其他 ruby​​ 版本管理系统。

Did you add the following lines to your ~/.bash_profile ?您是否将以下几行添加到您的~/.bash_profile

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

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

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-version in your current dir.该文件甚至可能是您当前目录中名为.ruby-version的隐藏文件。 If its the case just remove that .ruby-version file如果是这种情况,只需删除该.ruby-version文件

我意识到我偶尔会在主文件夹中设置本地 ruby​​ 版本,默认情况下我使用终端 :) 所以这对我有用:

rm /home/MYUSERNAME/.ruby-version

Run the below commands before change ruby version:在更改 ruby​​ 版本之前运行以下命令:

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

It works for me :)这个对我有用 :)

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 

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?你先试过吗?

If you are installing ruby on rails on ubuntu,and you rbenv doesn't change your ruby version如果您在 ubuntu 上的 rails 上安装 ruby​​,并且您的 rbenv 不会更改您的 ruby​​ 版本

> rbenv list # This lists all the rbenv versions available
  • 2.6.8 2.6.8
  • 2.7.4 2.7.4
  • 3.0.2 3.0.2
  • jruby-9.3.1.0 jruby-9.3.1.0
  • mruby-3.0.0 mruby-3.0.0
  • rbx-5.0 rbx-5.0
    -truffleruby-21.3.0 -truffleruby-21.3.0
    -truffleruby+graalvm-21.3.0 -truffleruby+graalvm-21.3.0

In my case I need to install ruby 3.0.2就我而言,我需要安装 ruby​​ 3.0.2

rbenv install 3.0.2

After this also it shows ruby v [2.7.0-]在此之后它也显示 ruby​​ v [2.7.0-]

rbenv global 3.0.2

This will help you change your ruby version.这将帮助您更改 ruby​​ 版本。

instead of:代替:
rbenv global 2.7.1 rbenv 全球 2.7.1
do:做:
sudo rbenv global 2.7.1须藤 rbenv 全球 2.7.1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM