我真正运行的是哪个 Ruby 版本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18549107/
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
Which Ruby version am I really running?
提问by Ordep81
I'm running Ubuntu 12.04 LTS, and installed Ruby via RVM.
我正在运行 Ubuntu 12.04 LTS,并通过 RVM 安装了 Ruby。
The problem is, when I type ruby -vinto the terminal, it says that my Ruby version is 1.8.7, and using the shotgun gem for Sinatra also says that I'm running Ruby 1.8.7.
问题是,当我输入ruby -v终端时,它说我的 Ruby 版本是1.8.7,并且使用 Sinatra 的猎枪 gem 也说我正在运行 Ruby 1.8.7。
But when I type rvm listit shows that the only version of Ruby that I have installed is 2.0.0and it is my current and default version.
但是当我输入时,rvm list它显示我安装的唯一 Ruby 版本2.0.0是我当前的默认版本。
I installed Ruby 2.0.0via RVM and it is the only version I had installed on my machine.
我2.0.0通过 RVM安装了 Ruby ,它是我在我的机器上安装的唯一版本。
Now when I tried to install Rails 4 but got an error saying that I need Ruby 1.9 or higher.
现在,当我尝试安装 Rails 4 但收到错误提示我需要 Ruby 1.9 或更高版本时。
How do I know what version am I really on, and how do I set 2.0.0as my only version?
我如何知道我真正使用的是哪个版本,以及如何设置2.0.0为我唯一的版本?
采纳答案by mpapis
Run this command:
运行此命令:
rvm get stable --auto-dotfiles
and make sure to read all the output. RVMwill tell you if something is wrong, which in your case might be because GEM_HOMEis set to something different then PATH.
并确保阅读所有输出。RVM会告诉您是否有问题,在您的情况下可能是因为GEM_HOME设置为不同的 then PATH。
回答by u1860929
On your terminal, try running:
在您的终端上,尝试运行:
which -a ruby
This will output all the installed Ruby versions (via RVM, or otherwise) on your system in your PATH. If 1.8.7 is your system Ruby version, you can uninstall the system Ruby using:
这将在 PATH 中输出系统上所有已安装的 Ruby 版本(通过 RVM 或其他方式)。如果 1.8.7 是您的系统 Ruby 版本,您可以使用以下命令卸载系统 Ruby:
sudo apt-get purge ruby
Once you have made sure you have Ruby installed via RVM alone, in your loginshell you can type:
确定单独通过 RVM 安装了 Ruby 后,login您可以在shell 中键入:
rvm --default use 2.0.0
You don't need to do this if you have only one Ruby version installed.
如果您只安装了一个 Ruby 版本,则无需执行此操作。
If you still face issues with any system Ruby files, try running:
如果您仍然遇到任何系统 Ruby 文件的问题,请尝试运行:
dpkg-query -l '*ruby*'
This will output a bunch of Ruby-related files and packages which are, or were, installed on your system at the system level. Check the status of each to find if any of them is native and is causing issues.
这将输出一堆与 Ruby 相关的文件和包,这些文件和包在系统级别安装在您的系统上。检查每个的状态以查看它们中是否有任何一个是本地的并导致问题。
回答by Matthias
The ruby version 1.8.7 seems to be your system ruby.
ruby 版本 1.8.7 似乎是您的系统 ruby。
Normally you can choose the ruby version you'd like, if you are using rvm with following. Simple change into your directory in a new terminal and type in:
通常你可以选择你喜欢的 ruby 版本,如果你正在使用 rvm 和以下。在新终端中简单地切换到您的目录并输入:
rvm use 2.0.0
You can find more details about rvm here: http://rvm.ioOpen the website and scroll down, you will see a few helpful links. "Setting up default rubies" for example could help you.
您可以在此处找到有关 rvm 的更多详细信息:http://rvm.io 打开网站并向下滚动,您将看到一些有用的链接。例如,“设置默认红宝石”可以帮助您。
Update:To set the ruby as default:
更新:将 ruby 设置为默认值:
rvm use 2.0.0 --default
回答by Ivar
If you have access to a console in the context you are investigating, you can determine which version you are running by printing the value of the global constant RUBY_VERSION.
如果您可以访问正在调查的上下文中的控制台,则可以通过打印 global constant 的值来确定您正在运行的版本RUBY_VERSION。

