Rails 未使用正确版本的 Ruby [英] Rails not using correct version of Ruby

查看:54
本文介绍了Rails 未使用正确版本的 Ruby的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新信息

rails 控制台 会发生这种情况:

Loading development environment (Rails 3.1.1)
ruby-1.9.2-p290 :001 > RUBY_VERSION
 => "1.8.7" 

这里发生了一些非常奇怪的事情 - 提示显示 1.9.2RUBY_VERSION 显示 1.8.7.

There's something really weird going on here - the prompt says 1.9.2 but RUBY_VERSION shows 1.8.7.

我正在使用 RVM,但我在 Ubuntu 上遇到 Rails 问题.

I'm using RVM, but I'm having problems with Rails on Ubuntu.

$ which ruby
/home/nick/.rvm/rubies/ruby-1.9.2-p290/bin/ruby

$rvm list
rvm rubies
=> ruby-1.9.2-p290 [ i686 ]

但是如果我做 gem env 我得到

But if I do gem env I get

RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.11
  - RUBY VERSION: 1.8.7 (2011-06-30 patchlevel 352) [i686-linux]
  - INSTALLATION DIRECTORY: /home/nick/.rvm/gems/ruby-1.9.2-p290
  - RUBY EXECUTABLE: /usr/bin/ruby1.8
  - EXECUTABLE DIRECTORY: /home/nick/.rvm/gems/ruby-1.9.2-p290/bin

当我运行 Rails 时,如果我执行 puts RUBY_VERSION 它会输出 1.8.7.

and when I run Rails, if I do puts RUBY_VERSION it outputs 1.8.7.

事实上,在 irb 中,RUBY_VERSION 给出了 1.9.2 但在 rails 控制台 中它给出了 1.8.7.

In fact, in irb, RUBY_VERSION gives 1.9.2 but in rails console it gives 1.8.7.

主要问题是当它到达我的 JSON 样式的散列文字时它失败了.

The main problem is that it's failing when it gets to my JSON-style hash-literals.

我尝试了各种卸载 rvm、rails、bundler 等的方法,但似乎没有任何效果.有什么想法吗?

I've tried various approaches of uninstalling rvm, rails, bundler, etc. but nothing seems to work. Any ideas?

这是rvm info的输出:

ruby-1.9.2-p290:

  system:
    uname:       "Linux ubie 3.0.0-12-generic #20-Ubuntu SMP Fri Oct 7 14:50:42 UTC 2011 i686 i686 i386 GNU/Linux"
    bash:        "/bin/bash => GNU bash, version 4.2.10(1)-release (i686-pc-linux-gnu)"
    zsh:         " => not installed"

  rvm:
    version:      "rvm 1.8.6 by Wayne E. Seguin (wayneeseguin@gmail.com) [https://rvm.beginrescueend.com/]"

  ruby:
    interpreter:  "ruby"
    version:      "1.9.2p290"
    date:         "2011-07-09"
    platform:     "i686-linux"
    patchlevel:   "2011-07-09 revision 32553"
    full_version: "ruby 1.9.2p290 (2011-07-09 revision 32553) [i686-linux]"

  homes:
    gem:          "/home/nick/.rvm/gems/ruby-1.9.2-p290"
    ruby:         "/home/nick/.rvm/rubies/ruby-1.9.2-p290"

  binaries:
    ruby:         "/home/nick/.rvm/rubies/ruby-1.9.2-p290/bin/ruby"
    irb:          "/home/nick/.rvm/rubies/ruby-1.9.2-p290/bin/irb"
    gem:          "/home/nick/.rvm/rubies/ruby-1.9.2-p290/bin/gem"
    rake:         "/home/nick/.rvm/gems/ruby-1.9.2-p290/bin/rake"

  environment:
    PATH:         "/home/nick/.rvm/gems/ruby-1.9.2-p290/bin:/home/nick/.rvm/gems/ruby-1.9.2-p290@global/bin:/home/nick/.rvm/rubies/ruby-1.9.2-p290/bin:/home/nick/.rvm/bin:/home/nick/local/node/bin:/home/nick/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
    GEM_HOME:     "/home/nick/.rvm/gems/ruby-1.9.2-p290"
    GEM_PATH:     "/home/nick/.rvm/gems/ruby-1.9.2-p290:/home/nick/.rvm/gems/ruby-1.9.2-p290@global"
    MY_RUBY_HOME: "/home/nick/.rvm/rubies/ruby-1.9.2-p290"
    IRBRC:        "/home/nick/.rvm/rubies/ruby-1.9.2-p290/.irbrc"
    RUBYOPT:      ""
    gemset:       ""

但仍然 gem env 告诉我在 RubyGems 环境中 Ruby 版本是 1.8.7.我就是不明白.

but still gem env tells me that in the RubyGems Environment the Ruby version is 1.8.7. I just don't get it.

推荐答案

你应该像这样设置默认的 ruby​​:

You should set default ruby like:

rvm use 1.9.2 --default

这将使用 rvm one 覆盖系统安装的 ruby​​.

This will override system installed ruby with rvm one.

更新:

notme,谢谢你的评论

notme, thank you for remark

默认前双连字符对于设置默认红宝石很重要.

Leading double hyphen before default is significant to set default ruby.

下面列出了详细的&不言自明的例子,享受:

Below listed detailed & self-explained example, enjoy:

$ruby -v
ruby 1.8.7 (2008-08-11 patchlevel 72) [i686-linux]

$rvm list
rvm rubies

   ruby-1.9.2-p290 [ i386 ]

$rvm use 1.9.2 --default
Using /usr/local/rvm/gems/ruby-1.9.2-p290

$rvm list default

Default Ruby (for new shells)

   ruby-1.9.2-p290 [ i386 ]

$rvm use default
Using /usr/local/rvm/gems/ruby-1.9.2-p290

$ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [i686-linux]

$rvm list 

rvm rubies

=> ruby-1.9.2-p290 [ i386 ]

这篇关于Rails 未使用正确版本的 Ruby的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆