简体   繁体   English

Rails使用了错误的Ruby版本

[英]Rails is using wrong version of Ruby

➜  ~  ruby -v
ruby 1.8.7 (2014-01-28 patchlevel 376) [i686-darwin15.0.0]

➜  ~  rails -v
Rails 2.3.18

➜  ~  gem environment
RubyGems Environment:
- RUBYGEMS VERSION: 2.0.17
- RUBY VERSION: 1.8.7 (2013-06-27 patchlevel 374) [i686-darwin15.0.0]
- INSTALLATION DIRECTORY: /Users/reboot/.rvm/gems/ruby-1.8.7-p374
- RUBY EXECUTABLE: /Users/reboot/.rvm/rubies/ruby-1.8.7-p374/bin/ruby
- EXECUTABLE DIRECTORY: /Users/reboot/.rvm/gems/ruby-1.8.7-p374/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-darwin-15
- GEM PATHS:
 - /Users/reboot/.rvm/gems/ruby-1.8.7-p374
 - /Users/reboot/.rvm/gems/ruby-1.8.7-p374@global
- GEM CONFIGURATION:
 - :update_sources => true
 - :verbose => true
 - :backtrace => false
 - :bulk_threshold => 1000
- REMOTE SOURCES:
 - https://rubygems.org/

But when I am running my code on IDE, I am getting following error: 但是,当我在IDE上运行代码时,出现以下错误:

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- cron_tools (LoadError)
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'

So from above error message, it looks like ruby 2.0.0 is being used. 因此,从上述错误消息看来,似乎正在使用ruby 2.0.0。 I am also not able to load the files due to some reason. 由于某些原因,我也无法加载文件。

How can I tell Rails to use Ruby 1.8.7. 如何告诉Rails使用Ruby 1.8.7。

I have already done rvm --default use 1.8.7 我已经完成了rvm --default use 1.8.7

Here is my path 这是我的路

➜  ~  echo $PATH
/Users/reboot/.rvm/gems/ruby-1.8.7-head/bin:/Users/reboot/.rvm/gems/ruby-1.8.7-head@global/bin:/Users/reboot/.rvm/rubies/ruby-1.8.7-head/bin:/Users/reboot/.rvm/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin


➜  ~  which ruby
/Users/reboot/.rvm/rubies/ruby-1.8.7-head/bin/ruby


➜  ~  which rails
/Users/reboot/.rvm/gems/ruby-1.8.7-head/bin/rails

ok so the problem was when I was using Rubymine to run a script it was using Ruby interpret, thats why it was not loading rails environment. 好的,问题是当我使用Rubymine运行脚本时,它使用的是Ruby解释,这就是为什么它没有加载rails环境。 Since my script was using Time.now - 1.month , where 1.month comes from Active Support, not Ruby stdlib thats why I was getting the error. 由于我的脚本使用的是Time.now - 1.month ,其中1.month来自Active Support,而不是Ruby stdlib,这就是我得到此错误的原因。 I fixed the problem by running the script from terminal 我通过从终端运行脚本解决了问题

./script/runner <filename>

and everything worked. 一切正常。

I also had to add this line at the beginning or my .zshrc file to fix the problem with Ruby version. 我还必须在开头或我的.zshrc文件中添加此行,以解决Ruby版本的问题。

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"

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

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