Search code examples
ruby-on-railsrubyrvmrubymine

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:

/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. I am also not able to load the files due to some reason.

How can I tell Rails to use Ruby 1.8.7.

I have already done 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

Solution

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

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