Rails 3 - Whenever gem error: /usr/bin/env: ruby: No such file or directory

Kevin picture Kevin · Nov 26, 2011 · Viewed 10.4k times · Source

When using the 'whenever gem', I get an error in the log:

/usr/bin/env: ruby: No such file or directory

It works when I run the job manually. I've installed everything with RVM.

I've used the which command to find where my Ruby installation is, and I get:

kevin@lovely:/opt/personal$ which ruby
/home/kevin/.rvm/rubies/ruby-1.9.2-p290/bin/ruby

and I've checked my $PATH variable, where it returns:

kevin@lovely:/opt/personal$ echo $PATH
/home/kevin/.rvm/gems/ruby-1.9.2-p290/bin:/home/kevin/.rvm/gems/ruby-1.9.2-p290@global/bin:/home/kevin/.rvm/rubies/ruby-1.9.2-p290/bin:/home/kevin/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

I believe this should be set up right, but I'm probably wrong since it doesn't work. Can anyone point me in the right direction?

If you're interested, this is what my whenever crontab output is:

# Begin Whenever generated tasks for: rss
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /bin/bash -l -c 'cd /opt/personal && script/rails runner -e development '\''FeedEntry.update_from_feed("http://lovely/blog/feed/")'\'' >> /opt/personal/log/feedzirra.log 2>&1'

Answer

Tamar picture Tamar · Aug 13, 2012

You're probably long past this issue but for future reference:

I had a similar problem only I was getting

/usr/bin/env: ruby: No such file or directory

It turned out the first line of the file script\rails was #!/usr/bin/env ruby1.9.1, which tells the system to invoke it with ruby1.9.1 as explained here. But it should have been #!/usr/bin/env ruby1.9.3 since that was the version I had installed.

Hope this helps someone in the future :)