0

I have a cron job that is a Ruby script. The problem is that the ruby executable is different than expected. Ruby was installed from source so it should be the new global default.

$ ssh root@example.com

root@example.com$ ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]

root@example.com$ which ruby
/usr/local/bin/ruby

I currently have my script displaying the current user, ruby path, and ruby version:

# whoami
root

# which ruby
/usr/bin/ruby

# ruby -v
ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]

How do I correct this problem?

Update: The top of the first Ruby file that is executed has this line:

#!/usr/bin/env ruby
masegaloeh
  • 18,236
  • 10
  • 57
  • 106
Andrew
  • 3,453
  • 9
  • 33
  • 36

1 Answers1

1

Set your $PATH so that the directory containing the version you want is listed first.

and/or

Change the first line in the script to point directly at the version of ruby you want:

#!/usr/bin/ruby
  • I tried both of those suggestions and unfortunately neither of them worked. Any more ideas? – Andrew Nov 07 '13 at 01:10
  • I realized that `/usr/bin/ruby` was a symlink to the old Ruby version so I removed it. Now I'm getting errors: `/bin/bash: ruby: command not found` – Andrew Nov 07 '13 at 01:12
  • I created a new symlink to the right Ruby and it's working, but I'd like to know why `cron` was caching this sort of thing (if you have an answer). – Andrew Nov 07 '13 at 01:14
  • Sounds like the `cron` user's PATH was finding the old version of ruby in `/usr/bin/ruby` first. – andrew Nov 07 '13 at 01:19