Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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'
like image 997
Kevin Avatar asked Nov 26 '11 20:11

Kevin


3 Answers

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 :)

like image 118
Tamar Avatar answered Nov 05 '22 13:11

Tamar


My issue was that ruby is in /usr/local/bin which is not in the path of a headless bash. So I just made my rake task line in schedule.rb:

job_type :rake, "cd :path && PATH=/usr/local/bin:$PATH RAILS_ENV=:environment bundle exec rake :task :output"
like image 20
Duke Avatar answered Nov 05 '22 12:11

Duke


I am successfully using whenever with RVM and bundler in production. Here are the relevant pieces of my capistrano setup that may help you:

# rvm and bundler integration 
require 'rvm/capistrano'
require 'bundler/capistrano'

# RVM environment
set :rvm_ruby_string, "ruby-1.9.2@mygemset"

# crontab
set :whenever_roles, :cron
set :whenever_command, "bundle exec whenever"
set :whenever_environment, defer { stage }
require 'whenever/capistrano'

The :whenever_environment setting is because I am using a multi-stage deployment setup. You can ignore that or set it to a string that matches your setup if needed.

Most of this information can be found at the whenever github page under the "Capistrano integration" and "RVM Integration" section headers in the README.

I hope that helps.

like image 1
phlipper Avatar answered Nov 05 '22 11:11

phlipper